Skip to main content

vortex_geo/extension/
mod.rs

1// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright the Vortex contributors
3
4pub(crate) mod coordinate;
5mod point;
6mod wkb;
7
8use std::fmt::Display;
9
10pub use point::*;
11pub use wkb::*;
12
13/// Extension metadata that is common to all the geospatial extension types.
14///
15/// Currently, this is just the coordinate reference system (CRS).
16/// We may wish to add a second field for edges interpretation in the future similar to
17/// the GeoArrow standard.
18#[derive(Clone, PartialEq, Eq, Hash, prost::Message)]
19pub struct GeoMetadata {
20    #[prost(optional, string, tag = "1")]
21    pub crs: Option<String>,
22}
23
24impl Display for GeoMetadata {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        match self.crs.as_ref() {
27            Some(crs) => write!(f, "Geometry(crs={crs})"),
28            None => write!(f, "Geometry(unreferenced)"),
29        }
30    }
31}
32
33#[cfg(test)]
34mod tests {
35    use prost::Message;
36
37    use crate::extension::GeoMetadata;
38
39    #[test]
40    fn test_metadata() {
41        let meta = GeoMetadata {
42            crs: Some("EPSG:4326".to_string()),
43        };
44
45        assert_eq!(meta.to_string(), "Geometry(crs=EPSG:4326)");
46        // round trip
47        let bytes = meta.encode_to_vec();
48        let decoded = GeoMetadata::decode(bytes.as_slice()).unwrap();
49        assert_eq!(decoded, meta);
50    }
51}