Skip to content
Merged
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ geo = "0.31.0"
geo-traits = "0.3.0"
geo-types = "0.7.19"
geoarrow = "0.8.0"
geoarrow-cast = "0.8.0"
get_dir = "0.5.0"
glob = "0.3.2"
goldenfile = "1"
Expand Down
1 change: 1 addition & 0 deletions vortex-geo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ geo = { workspace = true }
geo-traits = { workspace = true }
geo-types = { workspace = true }
geoarrow = { workspace = true }
geoarrow-cast = { workspace = true }
prost = { workspace = true }
vortex-array = { workspace = true }
vortex-error = { workspace = true }
Expand Down
18 changes: 18 additions & 0 deletions vortex-geo/src/extension/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-FileCopyrightText: Copyright the Vortex contributors

pub(crate) mod coordinate;
mod multipolygon;
mod point;
mod polygon;
mod wkb;
Expand All @@ -10,8 +11,13 @@ use std::fmt::Display;
use std::sync::Arc;

use geo_types::Geometry;
use geoarrow::array::GeoArrowArray;
use geoarrow::datatypes::Crs;
use geoarrow::datatypes::GeoArrowType;
use geoarrow::datatypes::Metadata;
use geoarrow::datatypes::WkbType;
use geoarrow_cast::cast::cast;
pub use multipolygon::*;
pub use point::*;
pub use polygon::*;
use vortex_array::ArrayRef;
Expand All @@ -20,6 +26,7 @@ use vortex_array::IntoArray;
use vortex_array::arrays::ConstantArray;
use vortex_array::arrays::ExtensionArray;
use vortex_array::arrays::extension::ExtensionArrayExt;
use vortex_array::arrow::FromArrowArray;
use vortex_array::scalar::Scalar;
use vortex_error::VortexResult;
use vortex_error::vortex_bail;
Expand All @@ -46,6 +53,8 @@ pub(crate) fn geometries(
point_geometries(&storage, ctx)
} else if ext.is::<Polygon>() {
polygon_geometries(&storage, ctx)
} else if ext.is::<MultiPolygon>() {
multipolygon_geometries(&storage, ctx)
} else {
vortex_bail!("geo: unsupported geometry extension {}", array.dtype())
}
Expand Down Expand Up @@ -95,6 +104,15 @@ pub(crate) fn geoarrow_metadata(geo_metadata: &GeoMetadata) -> Arc<Metadata> {
))
}

/// Serialize a native geometry array to WKB (a `WkbView` array) via geoarrow's cast.
/// Shared by the `to_wkb` methods on the geometry extension types.
pub(crate) fn geoarrow_to_wkb(geo_array: &dyn GeoArrowArray) -> VortexResult<ArrayRef> {
let wkb_type = GeoArrowType::WkbView(WkbType::new(geoarrow_metadata(&GeoMetadata::default())));
let wkb = cast(geo_array, &wkb_type)
.map_err(|e| vortex_err!("failed to cast geometry to WKB: {e}"))?;
ArrayRef::from_arrow(wkb.to_array_ref().as_ref(), false)
}

/// Recover [`GeoMetadata`] from GeoArrow metadata.
pub(crate) fn geo_metadata_from_arrow(metadata: &Metadata) -> GeoMetadata {
let crs = metadata.crs().crs_value().map(|value| {
Expand Down
Loading
Loading