parquet/geospatial/
statistics.rs

1// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements.  See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership.  The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License.  You may obtain a copy of the License at
8//
9//   http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied.  See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Geospatial statistics for Parquet files.
19//!
20//! This module provides functionality for working with geospatial statistics in Parquet files.
21//! It includes support for bounding boxes and geospatial statistics in column chunk metadata.
22
23use crate::{file::metadata::HeapSize, geospatial::bounding_box::BoundingBox};
24
25// ----------------------------------------------------------------------
26// Geospatial Statistics
27
28/// Represents geospatial statistics for a Parquet column or dataset.
29///
30/// This struct contains metadata about the spatial characteristics of geospatial data,
31/// including bounding box information and the types of geospatial geometries present.
32/// It's used to optimize spatial queries and provide spatial context for data analysis.
33///
34/// # Examples
35///
36/// ```
37/// use parquet::geospatial::statistics::GeospatialStatistics;
38/// use parquet::geospatial::bounding_box::BoundingBox;
39///
40/// // Statistics with bounding box
41/// let bbox = BoundingBox::new(0.0, 0.0, 100.0, 100.0);
42/// let stats = GeospatialStatistics::new(Some(bbox), Some(vec![1, 2, 3]));
43/// ```
44#[derive(Clone, Debug, PartialEq, Default)]
45pub struct GeospatialStatistics {
46    bbox: Option<BoundingBox>,
47    geospatial_types: Option<Vec<i32>>,
48}
49
50impl GeospatialStatistics {
51    /// Creates a new geospatial statistics instance with the specified data.
52    pub fn new(bbox: Option<BoundingBox>, geospatial_types: Option<Vec<i32>>) -> Self {
53        Self {
54            bbox,
55            geospatial_types,
56        }
57    }
58
59    /// Optional list of geometry type identifiers, where `None` represents lack of information
60    pub fn geospatial_types(&self) -> Option<&Vec<i32>> {
61        self.geospatial_types.as_ref()
62    }
63
64    /// Optional bounding defining the spatial extent, where `None` represents a lack of information.
65    pub fn bounding_box(&self) -> Option<&BoundingBox> {
66        self.bbox.as_ref()
67    }
68}
69
70impl HeapSize for GeospatialStatistics {
71    fn heap_size(&self) -> usize {
72        self.bbox.heap_size() + self.geospatial_types.heap_size()
73    }
74}