From 7b56226c1aa84896d3a1da23ea3ccf797a7e8371 Mon Sep 17 00:00:00 2001 From: Kyle Barron Date: Wed, 18 Sep 2024 23:29:16 +0200 Subject: [PATCH] WIP: separate wkb array from native trait --- benches/nybb.rs | 2 +- benches/wkb.rs | 2 +- python/geoarrow-core/src/interop/ewkb.rs | 6 +- .../src/interop/numpy/to_numpy.rs | 2 +- .../src/interop/shapely/from_shapely.rs | 4 +- .../src/interop/shapely/to_shapely.rs | 4 +- python/geoarrow-core/src/interop/wkb.rs | 12 +- python/pyo3-geoarrow/src/array.rs | 4 +- python/pyo3-geoarrow/src/chunked_array.rs | 4 +- python/pyo3-geoarrow/src/data_type.rs | 36 +- .../src/ffi/from_python/scalar.rs | 6 +- python/pyo3-geoarrow/src/scalar.rs | 16 +- src/algorithm/geo/affine_ops.rs | 10 +- src/algorithm/geo/area.rs | 11 +- src/algorithm/geo/bounding_rect.rs | 9 +- src/algorithm/geo/center.rs | 9 +- src/algorithm/geo/centroid.rs | 13 +- src/algorithm/geo/chaikin_smoothing.rs | 8 +- .../geo/chamberlain_duquette_area.rs | 13 +- src/algorithm/geo/contains.rs | 20 +- src/algorithm/geo/convex_hull.rs | 11 +- src/algorithm/geo/densify.rs | 8 +- src/algorithm/geo/dimensions.rs | 9 +- src/algorithm/geo/euclidean_distance.rs | 4 +- src/algorithm/geo/euclidean_length.rs | 6 +- src/algorithm/geo/frechet_distance.rs | 10 +- src/algorithm/geo/geodesic_area.rs | 25 +- src/algorithm/geo/geodesic_length.rs | 6 +- src/algorithm/geo/haversine_length.rs | 6 +- src/algorithm/geo/line_interpolate_point.rs | 12 +- src/algorithm/geo/line_locate_point.rs | 14 +- src/algorithm/geo/minimum_rotated_rect.rs | 8 +- src/algorithm/geo/remove_repeated_points.rs | 8 +- src/algorithm/geo/rotate.rs | 16 +- src/algorithm/geo/scale.rs | 8 +- src/algorithm/geo/simplify.rs | 12 +- src/algorithm/geo/simplify_vw.rs | 10 +- src/algorithm/geo/simplify_vw_preserve.rs | 8 +- src/algorithm/geo/skew.rs | 8 +- src/algorithm/geo/translate.rs | 6 +- src/algorithm/geo/vincenty_length.rs | 6 +- src/algorithm/geo/within.rs | 2 +- src/algorithm/geo_index/rtree.rs | 8 +- src/algorithm/geos/area.rs | 4 +- src/algorithm/geos/buffer.rs | 2 +- src/algorithm/geos/is_ring.rs | 7 +- src/algorithm/geos/is_valid.rs | 7 +- src/algorithm/geos/length.rs | 4 +- src/algorithm/native/binary.rs | 66 +-- src/algorithm/native/cast.rs | 72 ++- src/algorithm/native/concatenate.rs | 2 +- src/algorithm/native/downcast.rs | 137 +++--- src/algorithm/native/explode.rs | 8 +- src/algorithm/native/map_coords.rs | 8 +- src/algorithm/native/take.rs | 8 +- src/algorithm/native/total_bounds.rs | 32 +- src/algorithm/native/type_id.rs | 2 +- src/algorithm/native/unary.rs | 36 +- src/algorithm/polylabel.rs | 10 +- src/algorithm/proj.rs | 4 +- src/algorithm/rstar.rs | 2 +- src/array/binary/array.rs | 65 +-- src/array/cast.rs | 52 +- src/array/dynamic.rs | 32 +- src/array/geometry/array.rs | 8 +- src/array/geometrycollection/array.rs | 58 +-- src/array/geometrycollection/builder.rs | 2 +- src/array/linestring/array.rs | 56 +-- src/array/linestring/builder.rs | 2 +- src/array/mixed/array.rs | 58 +-- src/array/mixed/builder.rs | 4 +- src/array/mod.rs | 13 +- src/array/multilinestring/array.rs | 58 +-- src/array/multilinestring/builder.rs | 2 +- src/array/multipoint/array.rs | 56 +-- src/array/multipoint/builder.rs | 2 +- src/array/multipolygon/array.rs | 56 +-- src/array/multipolygon/builder.rs | 2 +- src/array/point/array.rs | 54 ++- src/array/point/builder.rs | 2 +- src/array/polygon/array.rs | 56 +-- src/array/polygon/builder.rs | 2 +- src/array/rect/array.rs | 54 ++- src/chunked_array.rs | 36 +- src/datatypes.rs | 446 ++++++++++++------ src/indexed/array.rs | 10 +- src/io/display/array.rs | 2 +- src/io/display/chunked_array.rs | 2 +- src/io/display/scalar.rs | 2 +- src/io/geos/array/linestring.rs | 2 +- src/io/geos/array/multilinestring.rs | 2 +- src/io/geos/array/multipoint.rs | 2 +- src/io/geos/array/multipolygon.rs | 2 +- src/io/geos/array/point.rs | 2 +- src/io/geos/array/polygon.rs | 2 +- src/io/geos/scalar/point.rs | 2 +- src/io/geozero/api/wkt.rs | 6 +- src/io/geozero/array/dynamic.rs | 6 +- src/io/geozero/array/geometrycollection.rs | 4 +- src/io/geozero/array/linestring.rs | 6 +- src/io/geozero/array/mixed.rs | 3 +- src/io/geozero/array/multilinestring.rs | 6 +- src/io/geozero/array/multipoint.rs | 6 +- src/io/geozero/array/multipolygon.rs | 6 +- src/io/geozero/array/point.rs | 6 +- src/io/geozero/array/polygon.rs | 6 +- src/io/geozero/scalar/geometry.rs | 4 +- src/io/geozero/scalar/geometry_array.rs | 30 +- src/io/geozero/table/data_source.rs | 22 +- src/io/parquet/metadata.rs | 69 ++- src/io/parquet/reader/parse.rs | 101 ++-- src/io/parquet/reader/spatial_filter.rs | 2 +- src/io/parquet/writer/encode.rs | 2 +- src/io/parquet/writer/metadata.rs | 97 ++-- src/io/wkb/api.rs | 31 +- src/io/wkb/reader/type.rs | 38 +- src/io/wkb/writer/geometry.rs | 4 +- src/io/wkb/writer/geometrycollection.rs | 4 +- src/io/wkb/writer/linestring.rs | 4 +- src/io/wkb/writer/multilinestring.rs | 4 +- src/io/wkb/writer/multipoint.rs | 4 +- src/io/wkb/writer/multipolygon.rs | 4 +- src/io/wkb/writer/point.rs | 4 +- src/io/wkb/writer/polygon.rs | 6 +- src/lib.rs | 2 +- src/scalar/geometrycollection/scalar.rs | 2 +- src/scalar/linestring/scalar.rs | 2 +- src/scalar/multilinestring/scalar.rs | 2 +- src/scalar/multipoint/scalar.rs | 2 +- src/scalar/multipolygon/scalar.rs | 2 +- src/scalar/point/scalar.rs | 2 +- src/scalar/polygon/scalar.rs | 2 +- src/scalar/scalar.rs | 66 ++- src/table.rs | 24 +- src/test/point.rs | 2 +- src/trait_.rs | 180 ++++--- 136 files changed, 1418 insertions(+), 1374 deletions(-) diff --git a/benches/nybb.rs b/benches/nybb.rs index c86e63b2f..954675642 100644 --- a/benches/nybb.rs +++ b/benches/nybb.rs @@ -4,7 +4,7 @@ use arrow_ipc::reader::FileReader; use criterion::{criterion_group, criterion_main, Criterion}; use geoarrow::algorithm::geo::EuclideanDistance; use geoarrow::array::{MultiPolygonArray, PointArray}; -use geoarrow::trait_::NativeArrayAccessor; +use geoarrow::trait_::ArrayAccessor; fn load_nybb() -> MultiPolygonArray { let file = File::open("fixtures/nybb.arrow").unwrap(); diff --git a/benches/wkb.rs b/benches/wkb.rs index f85afdef1..270e912cf 100644 --- a/benches/wkb.rs +++ b/benches/wkb.rs @@ -3,7 +3,7 @@ use std::fs::File; use arrow::compute::concat; use criterion::{criterion_group, criterion_main, Criterion}; use geoarrow::array::{MultiPolygonArray, WKBArray}; -use geoarrow::trait_::NativeArrayAccessor; +use geoarrow::trait_::ArrayAccessor; use parquet::arrow::arrow_reader::ParquetRecordBatchReaderBuilder; use parquet::arrow::ProjectionMask; diff --git a/python/geoarrow-core/src/interop/ewkb.rs b/python/geoarrow-core/src/interop/ewkb.rs index a3c35e20d..cf39cb21b 100644 --- a/python/geoarrow-core/src/interop/ewkb.rs +++ b/python/geoarrow-core/src/interop/ewkb.rs @@ -1,7 +1,7 @@ use std::sync::Arc; use geoarrow::array::{from_arrow_array, AsNativeArray, CoordType}; -use geoarrow::datatypes::GeoDataType; +use geoarrow::datatypes::NativeType; use geoarrow::io::geozero::FromEWKB; use geoarrow::NativeArray; use pyo3::exceptions::PyTypeError; @@ -17,13 +17,13 @@ pub fn from_ewkb(py: Python, input: PyArray) -> PyGeoArrowResult { let array = from_arrow_array(&array, &field)?; let ref_array = array.as_ref(); let geo_array: Arc = match array.data_type() { - GeoDataType::WKB => FromEWKB::from_ewkb( + NativeType::WKB => FromEWKB::from_ewkb( ref_array.as_wkb(), CoordType::Interleaved, Default::default(), false, )?, - GeoDataType::LargeWKB => FromEWKB::from_ewkb( + NativeType::LargeWKB => FromEWKB::from_ewkb( ref_array.as_large_wkb(), CoordType::Interleaved, Default::default(), diff --git a/python/geoarrow-core/src/interop/numpy/to_numpy.rs b/python/geoarrow-core/src/interop/numpy/to_numpy.rs index 744404a19..ba728f3f8 100644 --- a/python/geoarrow-core/src/interop/numpy/to_numpy.rs +++ b/python/geoarrow-core/src/interop/numpy/to_numpy.rs @@ -1,4 +1,4 @@ -use geoarrow::trait_::NativeArrayAccessor; +use geoarrow::trait_::ArrayAccessor; use geoarrow::NativeArray; use pyo3::exceptions::PyValueError; use pyo3::intern; diff --git a/python/geoarrow-core/src/interop/shapely/from_shapely.rs b/python/geoarrow-core/src/interop/shapely/from_shapely.rs index 77d77f556..18c0b9545 100644 --- a/python/geoarrow-core/src/interop/shapely/from_shapely.rs +++ b/python/geoarrow-core/src/interop/shapely/from_shapely.rs @@ -7,7 +7,7 @@ use arrow_array::builder::{BinaryBuilder, Int32BufferBuilder}; use arrow_buffer::OffsetBuffer; use geoarrow::array::metadata::ArrayMetadata; use geoarrow::array::InterleavedCoordBuffer; -use geoarrow::datatypes::{Dimension, GeoDataType}; +use geoarrow::datatypes::{Dimension, NativeType}; use geoarrow::NativeArray; use numpy::{PyReadonlyArray1, PyReadonlyArray2, PyUntypedArrayMethods}; use pyo3::exceptions::PyValueError; @@ -126,7 +126,7 @@ pub fn from_shapely( let wkb_arr = make_wkb_arr(py, input, metadata)?; let geom_arr = geoarrow::io::wkb::from_wkb( &wkb_arr, - GeoDataType::GeometryCollection(Default::default(), Dimension::XY), + NativeType::GeometryCollection(Default::default(), Dimension::XY), false, )?; geometry_array_to_pyobject(py, geom_arr) diff --git a/python/geoarrow-core/src/interop/shapely/to_shapely.rs b/python/geoarrow-core/src/interop/shapely/to_shapely.rs index 8d7a36d9d..288544dbb 100644 --- a/python/geoarrow-core/src/interop/shapely/to_shapely.rs +++ b/python/geoarrow-core/src/interop/shapely/to_shapely.rs @@ -5,7 +5,7 @@ use crate::interop::shapely::utils::import_shapely; use arrow_array::OffsetSizeTrait; use arrow_buffer::NullBuffer; use geoarrow::array::{from_arrow_array, AsNativeArray, CoordBuffer}; -use geoarrow::datatypes::{Dimension, GeoDataType}; +use geoarrow::datatypes::{Dimension, NativeType}; use geoarrow::io::wkb::to_wkb; use geoarrow::NativeArray; use numpy::PyArrayMethods; @@ -87,7 +87,7 @@ fn pyarray_to_shapely(py: Python, input: PyArray) -> PyGeoArrowResult point_arr(py, array.as_ref().as_point::<2>().clone()), LineString(_, XY) => linestring_arr(py, array.as_ref().as_line_string::<2>().clone()), diff --git a/python/geoarrow-core/src/interop/wkb.rs b/python/geoarrow-core/src/interop/wkb.rs index 22fb8a2b9..f11055730 100644 --- a/python/geoarrow-core/src/interop/wkb.rs +++ b/python/geoarrow-core/src/interop/wkb.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use geoarrow::array::{AsChunkedNativeArray, AsNativeArray, NativeArrayDyn}; use geoarrow::chunked_array::ChunkedNativeArray; -use geoarrow::datatypes::GeoDataType; +use geoarrow::datatypes::NativeType; use geoarrow::error::GeoArrowError; use geoarrow::io::wkb::{to_wkb as _to_wkb, FromWKB, ToWKB}; use geoarrow::NativeArray; @@ -27,10 +27,8 @@ pub fn from_wkb( match input { AnyGeometryInput::Array(arr) => { let geo_array: Arc = match arr.as_ref().data_type() { - GeoDataType::WKB => FromWKB::from_wkb(arr.as_ref().as_wkb(), coord_type)?, - GeoDataType::LargeWKB => { - FromWKB::from_wkb(arr.as_ref().as_large_wkb(), coord_type)? - } + NativeType::WKB => FromWKB::from_wkb(arr.as_ref().as_wkb(), coord_type)?, + NativeType::LargeWKB => FromWKB::from_wkb(arr.as_ref().as_large_wkb(), coord_type)?, other => { return Err(GeoArrowError::IncorrectType( format!("Unexpected array type {:?}", other).into(), @@ -42,8 +40,8 @@ pub fn from_wkb( } AnyGeometryInput::Chunked(s) => { let geo_array: Arc = match s.as_ref().data_type() { - GeoDataType::WKB => FromWKB::from_wkb(s.as_ref().as_wkb(), coord_type)?, - GeoDataType::LargeWKB => FromWKB::from_wkb(s.as_ref().as_large_wkb(), coord_type)?, + NativeType::WKB => FromWKB::from_wkb(s.as_ref().as_wkb(), coord_type)?, + NativeType::LargeWKB => FromWKB::from_wkb(s.as_ref().as_large_wkb(), coord_type)?, other => { return Err(GeoArrowError::IncorrectType( format!("Unexpected array type {:?}", other).into(), diff --git a/python/pyo3-geoarrow/src/array.rs b/python/pyo3-geoarrow/src/array.rs index c0b08c86c..f45dba2d8 100644 --- a/python/pyo3-geoarrow/src/array.rs +++ b/python/pyo3-geoarrow/src/array.rs @@ -7,7 +7,7 @@ use arrow_array::RecordBatch; use geoarrow::array::{from_arrow_array, NativeArrayDyn}; use geoarrow::error::GeoArrowError; -use geoarrow::scalar::GeometryScalar; +use geoarrow::scalar::NativeScalar; use geoarrow::trait_::NativeArrayRef; use geoarrow::NativeArray; use geozero::ProcessToJson; @@ -114,7 +114,7 @@ impl PyGeometryArray { } Ok(Some(PyGeometry( - GeometryScalar::try_new(self.0.slice(i, 1)).unwrap(), + NativeScalar::try_new(self.0.slice(i, 1)).unwrap(), ))) } diff --git a/python/pyo3-geoarrow/src/chunked_array.rs b/python/pyo3-geoarrow/src/chunked_array.rs index ef52271a9..2b9c32b62 100644 --- a/python/pyo3-geoarrow/src/chunked_array.rs +++ b/python/pyo3-geoarrow/src/chunked_array.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use geoarrow::array::from_arrow_array; use geoarrow::chunked_array::{from_arrow_chunks, ChunkedNativeArray}; -use geoarrow::scalar::GeometryScalar; +use geoarrow::scalar::NativeScalar; use pyo3::exceptions::PyIndexError; use pyo3::intern; use pyo3::prelude::*; @@ -91,7 +91,7 @@ impl PyChunkedGeometryArray { let geom_chunks = sliced.geometry_chunks(); assert_eq!(geom_chunks.len(), 1); Ok(Some(PyGeometry( - GeometryScalar::try_new(geom_chunks[0].clone()).unwrap(), + NativeScalar::try_new(geom_chunks[0].clone()).unwrap(), ))) } diff --git a/python/pyo3-geoarrow/src/data_type.rs b/python/pyo3-geoarrow/src/data_type.rs index 83ba0d66b..f5170bcd6 100644 --- a/python/pyo3-geoarrow/src/data_type.rs +++ b/python/pyo3-geoarrow/src/data_type.rs @@ -2,7 +2,7 @@ use crate::error::{PyGeoArrowError, PyGeoArrowResult}; use crate::{PyCoordType, PyDimension}; use geoarrow::array::CoordType; -use geoarrow::datatypes::{Dimension, GeoDataType}; +use geoarrow::datatypes::{Dimension, NativeType}; use pyo3::exceptions::PyValueError; use pyo3::intern; use pyo3::prelude::*; @@ -11,10 +11,10 @@ use pyo3_arrow::ffi::to_schema_pycapsule; use pyo3_arrow::PyField; #[pyclass(module = "geoarrow.rust.core._rust", name = "GeometryType", subclass)] -pub struct PyGeometryType(pub(crate) GeoDataType); +pub struct PyGeometryType(pub(crate) NativeType); impl PyGeometryType { - pub fn new(data_type: GeoDataType) -> Self { + pub fn new(data_type: NativeType) -> Self { Self(data_type) } @@ -23,7 +23,7 @@ impl PyGeometryType { PyField::from_arrow_pycapsule(capsule)?.try_into() } - pub fn into_inner(self) -> GeoDataType { + pub fn into_inner(self) -> NativeType { self.0 } } @@ -37,40 +37,40 @@ impl PyGeometryType { coord_type: Option, ) -> PyResult { match r#type.to_lowercase().as_str() { - "point" => Ok(Self(GeoDataType::Point( + "point" => Ok(Self(NativeType::Point( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "linestring" => Ok(Self(GeoDataType::LineString( + "linestring" => Ok(Self(NativeType::LineString( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "polygon" => Ok(Self(GeoDataType::Polygon( + "polygon" => Ok(Self(NativeType::Polygon( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "multipoint" => Ok(Self(GeoDataType::MultiPoint( + "multipoint" => Ok(Self(NativeType::MultiPoint( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "multilinestring" => Ok(Self(GeoDataType::MultiLineString( + "multilinestring" => Ok(Self(NativeType::MultiLineString( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "multipolygon" => Ok(Self(GeoDataType::MultiPolygon( + "multipolygon" => Ok(Self(NativeType::MultiPolygon( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "geometry" => Ok(Self(GeoDataType::Mixed( + "geometry" => Ok(Self(NativeType::Mixed( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "geometrycollection" => Ok(Self(GeoDataType::GeometryCollection( + "geometrycollection" => Ok(Self(NativeType::GeometryCollection( coord_type.unwrap().into(), dimension.unwrap().into(), ))), - "wkb" => Ok(Self(GeoDataType::WKB)), - "box" | "rect" => Ok(Self(GeoDataType::Rect(dimension.unwrap().into()))), + "wkb" => Ok(Self(NativeType::WKB)), + "box" | "rect" => Ok(Self(NativeType::Rect(dimension.unwrap().into()))), _ => Err(PyValueError::new_err("Unknown geometry type input")), } } @@ -87,7 +87,7 @@ impl PyGeometryType { } fn __repr__(&self) -> String { - // TODO: implement Display for GeoDataType + // TODO: implement Display for NativeType format!("geoarrow.rust.core.GeometryType({:?})", self.0) } @@ -130,13 +130,13 @@ impl PyGeometryType { } } -impl From for PyGeometryType { - fn from(value: GeoDataType) -> Self { +impl From for PyGeometryType { + fn from(value: NativeType) -> Self { Self(value) } } -impl From for GeoDataType { +impl From for NativeType { fn from(value: PyGeometryType) -> Self { value.0 } diff --git a/python/pyo3-geoarrow/src/ffi/from_python/scalar.rs b/python/pyo3-geoarrow/src/ffi/from_python/scalar.rs index a181dccf4..b3ad4e5f4 100644 --- a/python/pyo3-geoarrow/src/ffi/from_python/scalar.rs +++ b/python/pyo3-geoarrow/src/ffi/from_python/scalar.rs @@ -4,7 +4,7 @@ use crate::array::*; use crate::scalar::*; use geoarrow::array::MixedGeometryArray; use geoarrow::io::geozero::ToMixedArray; -use geoarrow::scalar::GeometryScalar; +use geoarrow::scalar::NativeScalar; use geozero::geojson::GeoJsonString; use pyo3::exceptions::PyValueError; use pyo3::prelude::*; @@ -16,7 +16,7 @@ impl<'a> FromPyObject<'a> for PyGeometry { let py = ob.py(); // TODO: direct shapely conversion not via __geo_interface__ if let Ok(geo_arr) = ob.extract::() { - let scalar = GeometryScalar::try_new(geo_arr.0.into_inner()).unwrap(); + let scalar = NativeScalar::try_new(geo_arr.0.into_inner()).unwrap(); Ok(PyGeometry::new(scalar)) } else if ob.hasattr(intern!(py, "__geo_interface__"))? { let json_string = call_geo_interface(py, ob)?; @@ -29,7 +29,7 @@ impl<'a> FromPyObject<'a> for PyGeometry { .to_mixed_geometry_array() .map_err(|err| PyValueError::new_err(err.to_string()))?; Ok(Self( - GeometryScalar::try_new(Arc::new(arr)) + NativeScalar::try_new(Arc::new(arr)) .map_err(|err| PyValueError::new_err(err.to_string()))?, )) } else { diff --git a/python/pyo3-geoarrow/src/scalar.rs b/python/pyo3-geoarrow/src/scalar.rs index 5a1964521..5c349a2a2 100644 --- a/python/pyo3-geoarrow/src/scalar.rs +++ b/python/pyo3-geoarrow/src/scalar.rs @@ -1,6 +1,6 @@ use geoarrow::algorithm::native::bounding_rect::bounding_rect_geometry; use geoarrow::error::GeoArrowError; -use geoarrow::scalar::GeometryScalar; +use geoarrow::scalar::NativeScalar; use geoarrow::NativeArray; use geozero::svg::SvgWriter; use geozero::{FeatureProcessor, GeozeroGeometry, ToJson}; @@ -14,18 +14,18 @@ use crate::error::PyGeoArrowResult; /// This is modeled as a geospatial array of length 1 #[pyclass(module = "geoarrow.rust.core._rust", name = "Geometry", subclass)] -pub struct PyGeometry(pub(crate) GeometryScalar); +pub struct PyGeometry(pub(crate) NativeScalar); impl PyGeometry { - pub fn new(array: GeometryScalar) -> Self { + pub fn new(array: NativeScalar) -> Self { Self(array) } - pub fn inner(&self) -> &GeometryScalar { + pub fn inner(&self) -> &NativeScalar { &self.0 } - pub fn into_inner(self) -> GeometryScalar { + pub fn into_inner(self) -> NativeScalar { self.0 } @@ -114,13 +114,13 @@ impl PyGeometry { } } -impl From for PyGeometry { - fn from(value: GeometryScalar) -> Self { +impl From for PyGeometry { + fn from(value: NativeScalar) -> Self { Self(value) } } -impl From for GeometryScalar { +impl From for NativeScalar { fn from(value: PyGeometry) -> Self { value.0 } diff --git a/src/algorithm/geo/affine_ops.rs b/src/algorithm/geo/affine_ops.rs index 5a53d5e1e..621d0799e 100644 --- a/src/algorithm/geo/affine_ops.rs +++ b/src/algorithm/geo/affine_ops.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::{AffineTransform, MapCoords}; @@ -132,7 +132,7 @@ impl AffineOps<&AffineTransform> for &dyn NativeArray { }; } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_downcast!(as_point), @@ -203,7 +203,7 @@ impl AffineOps<&AffineTransform> for &dyn ChunkedNativeArray { }; } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_downcast!(as_point), @@ -313,7 +313,7 @@ impl AffineOps<&[AffineTransform]> for &dyn NativeArray { fn affine_transform(&self, transform: &[AffineTransform]) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().affine_transform(transform)), diff --git a/src/algorithm/geo/area.rs b/src/algorithm/geo/area.rs index 9266359e8..aeed01104 100644 --- a/src/algorithm/geo/area.rs +++ b/src/algorithm/geo/area.rs @@ -2,9 +2,10 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; +// use crate::array::ArrayBase; use crate::NativeArray; use arrow_array::{Float64Array, OffsetSizeTrait}; use geo::prelude::Area as GeoArea; @@ -111,7 +112,7 @@ impl Area for &dyn NativeArray { fn signed_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().signed_area(), @@ -138,7 +139,7 @@ impl Area for &dyn NativeArray { fn unsigned_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().unsigned_area(), @@ -183,7 +184,7 @@ impl Area for &dyn ChunkedNativeArray { fn signed_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().signed_area(), @@ -209,7 +210,7 @@ impl Area for &dyn ChunkedNativeArray { fn unsigned_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().unsigned_area(), diff --git a/src/algorithm/geo/bounding_rect.rs b/src/algorithm/geo/bounding_rect.rs index 506870119..5019da7d4 100644 --- a/src/algorithm/geo/bounding_rect.rs +++ b/src/algorithm/geo/bounding_rect.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::algorithm::bounding_rect::BoundingRect as GeoBoundingRect; @@ -74,14 +74,13 @@ iter_geo_impl!(MultiLineStringArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl BoundingRect for &dyn NativeArray { type Output = Result>; fn bounding_rect(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().bounding_rect(), @@ -121,7 +120,7 @@ impl BoundingRect for &dyn ChunkedNativeArray { fn bounding_rect(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().bounding_rect(), diff --git a/src/algorithm/geo/center.rs b/src/algorithm/geo/center.rs index e9e80b6b7..2707bf86b 100644 --- a/src/algorithm/geo/center.rs +++ b/src/algorithm/geo/center.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray, ChunkedPointArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::BoundingRect; @@ -52,14 +52,13 @@ iter_geo_impl!(MultiLineStringArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl Center for &dyn NativeArray { type Output = Result>; fn center(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().center(), @@ -96,7 +95,7 @@ impl Center for &dyn ChunkedNativeArray { fn center(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().center(), diff --git a/src/algorithm/geo/centroid.rs b/src/algorithm/geo/centroid.rs index 02a7233da..0b867c388 100644 --- a/src/algorithm/geo/centroid.rs +++ b/src/algorithm/geo/centroid.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray, ChunkedPointArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::algorithm::centroid::Centroid as GeoCentroid; @@ -20,7 +20,7 @@ use geo::algorithm::centroid::Centroid as GeoCentroid; /// ``` /// use geoarrow::algorithm::geo::Centroid; /// use geoarrow::array::PolygonArray; -/// use geoarrow::trait_::NativeArrayAccessor; +/// use geoarrow::trait_::ArrayAccessor; /// use geo::{point, polygon}; /// /// // rhombus shaped polygon @@ -48,7 +48,7 @@ pub trait Centroid { /// ``` /// use geoarrow::algorithm::geo::Centroid; /// use geoarrow::array::LineStringArray; - /// use geoarrow::trait_::NativeArrayAccessor; + /// use geoarrow::trait_::ArrayAccessor; /// use geo::{line_string, point}; /// /// let line_string = line_string![ @@ -97,14 +97,13 @@ iter_geo_impl!(MultiLineStringArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl Centroid for &dyn NativeArray { type Output = Result>; fn centroid(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().centroid(), @@ -141,7 +140,7 @@ impl Centroid for &dyn ChunkedNativeArray { fn centroid(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().centroid(), diff --git a/src/algorithm/geo/chaikin_smoothing.rs b/src/algorithm/geo/chaikin_smoothing.rs index b45626142..80c9cc4db 100644 --- a/src/algorithm/geo/chaikin_smoothing.rs +++ b/src/algorithm/geo/chaikin_smoothing.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::ChaikinSmoothing as _ChaikinSmoothing; @@ -57,7 +57,7 @@ impl ChaikinSmoothing for &dyn NativeArray { fn chaikin_smoothing(&self, n_iterations: u32) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { LineString(_, XY) => { @@ -116,7 +116,7 @@ impl ChaikinSmoothing for &dyn ChunkedNativeArray { fn chaikin_smoothing(&self, n_iterations: u32) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { LineString(_, XY) => { diff --git a/src/algorithm/geo/chamberlain_duquette_area.rs b/src/algorithm/geo/chamberlain_duquette_area.rs index 0026cfbb1..051191822 100644 --- a/src/algorithm/geo/chamberlain_duquette_area.rs +++ b/src/algorithm/geo/chamberlain_duquette_area.rs @@ -1,9 +1,9 @@ use crate::algorithm::geo::utils::zeroes; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::builder::Float64Builder; use arrow_array::{Float64Array, OffsetSizeTrait}; @@ -130,14 +130,13 @@ iter_geo_impl!(PolygonArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl ChamberlainDuquetteArea for &dyn NativeArray { type Output = Result; fn chamberlain_duquette_signed_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().chamberlain_duquette_signed_area(), @@ -186,7 +185,7 @@ impl ChamberlainDuquetteArea for &dyn NativeArray { fn chamberlain_duquette_unsigned_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().chamberlain_duquette_unsigned_area(), @@ -261,7 +260,7 @@ impl ChamberlainDuquetteArea for &dyn ChunkedNativeArray { fn chamberlain_duquette_signed_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().chamberlain_duquette_signed_area(), @@ -309,7 +308,7 @@ impl ChamberlainDuquetteArea for &dyn ChunkedNativeArray { fn chamberlain_duquette_unsigned_area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().chamberlain_duquette_unsigned_area(), diff --git a/src/algorithm/geo/contains.rs b/src/algorithm/geo/contains.rs index 3219c2b6e..ed4ea7ffa 100644 --- a/src/algorithm/geo/contains.rs +++ b/src/algorithm/geo/contains.rs @@ -1,6 +1,6 @@ use crate::algorithm::native::{Binary, Unary}; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::GeoArrowError; use crate::geo_traits::{ GeometryCollectionTrait, GeometryTrait, LineStringTrait, MultiLineStringTrait, MultiPointTrait, @@ -10,7 +10,7 @@ use crate::io::geo::{ geometry_collection_to_geo, geometry_to_geo, line_string_to_geo, multi_line_string_to_geo, multi_point_to_geo, multi_polygon_to_geo, point_to_geo, polygon_to_geo, }; -use crate::trait_::{NativeArrayAccessor, NativeScalar}; +use crate::trait_::{ArrayAccessor, NativeScalar}; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; use arrow_array::{BooleanArray, OffsetSizeTrait}; @@ -168,7 +168,7 @@ impl_contains_point!(GeometryCollectionArray); impl> ContainsPoint for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsPoint::contains(self.as_point::<2>(), rhs), @@ -246,7 +246,7 @@ impl_contains_line_string!(GeometryCollectionArray); impl> ContainsLineString for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsLineString::contains(self.as_point::<2>(), rhs), @@ -318,7 +318,7 @@ impl_contains_polygon!(GeometryCollectionArray); impl> ContainsPolygon for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsPolygon::contains(self.as_point::<2>(), rhs), @@ -390,7 +390,7 @@ impl_contains_multi_point!(GeometryCollectionArray); impl> ContainsMultiPoint for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsMultiPoint::contains(self.as_point::<2>(), rhs), @@ -464,7 +464,7 @@ impl_contains_multi_line_string!(GeometryCollectionArray); impl> ContainsMultiLineString for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsMultiLineString::contains(self.as_point::<2>(), rhs), @@ -540,7 +540,7 @@ impl_contains_multi_polygon!(GeometryCollectionArray); impl> ContainsMultiPolygon for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsMultiPolygon::contains(self.as_point::<2>(), rhs), @@ -616,7 +616,7 @@ impl_contains_geometry!(GeometryCollectionArray); impl> ContainsGeometry for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsGeometry::contains(self.as_point::<2>(), rhs), @@ -692,7 +692,7 @@ impl_contains_geometry_collection!(GeometryCollectionArray); impl> ContainsGeometryCollection for &dyn NativeArray { fn contains(&self, rhs: &G) -> BooleanArray { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => ContainsGeometryCollection::contains(self.as_point::<2>(), rhs), diff --git a/src/algorithm/geo/convex_hull.rs b/src/algorithm/geo/convex_hull.rs index 2a405725b..55cb647fc 100644 --- a/src/algorithm/geo/convex_hull.rs +++ b/src/algorithm/geo/convex_hull.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray, ChunkedPolygonArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::algorithm::convex_hull::ConvexHull as GeoConvexHull; @@ -88,14 +88,13 @@ iter_geo_impl!(MultiLineStringArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl ConvexHull for &dyn NativeArray { type Output = Result>; fn convex_hull(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().convex_hull(), @@ -135,7 +134,7 @@ impl ConvexHull for &dyn ChunkedNativeArray { fn convex_hull(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().convex_hull(), @@ -165,7 +164,7 @@ mod tests { use super::ConvexHull; use crate::array::polygon::PolygonArray; use crate::array::{LineStringArray, MultiPointArray}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geo::{line_string, polygon, MultiPoint, Point}; #[test] diff --git a/src/algorithm/geo/densify.rs b/src/algorithm/geo/densify.rs index 75501cc79..5dc19c93b 100644 --- a/src/algorithm/geo/densify.rs +++ b/src/algorithm/geo/densify.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::Densify as _Densify; @@ -59,7 +59,7 @@ impl Densify for &dyn NativeArray { fn densify(&self, max_distance: f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { LineString(_, XY) => Arc::new(self.as_line_string::<2>().densify(max_distance)), @@ -108,7 +108,7 @@ impl Densify for &dyn ChunkedNativeArray { fn densify(&self, max_distance: f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { LineString(_, XY) => Arc::new(self.as_line_string::<2>().densify(max_distance)), diff --git a/src/algorithm/geo/dimensions.rs b/src/algorithm/geo/dimensions.rs index cc5d13039..806302ab7 100644 --- a/src/algorithm/geo/dimensions.rs +++ b/src/algorithm/geo/dimensions.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; use arrow_array::{BooleanArray, OffsetSizeTrait}; @@ -70,14 +70,13 @@ iter_geo_impl!(MultiLineStringArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl HasDimensions for &dyn NativeArray { type Output = Result; fn is_empty(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => HasDimensions::is_empty(self.as_point::<2>()), @@ -121,7 +120,7 @@ impl HasDimensions for &dyn ChunkedNativeArray { fn is_empty(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => HasDimensions::is_empty(self.as_point::<2>()), diff --git a/src/algorithm/geo/euclidean_distance.rs b/src/algorithm/geo/euclidean_distance.rs index b2b0d3051..45c91f543 100644 --- a/src/algorithm/geo/euclidean_distance.rs +++ b/src/algorithm/geo/euclidean_distance.rs @@ -1,7 +1,7 @@ use crate::array::*; use crate::scalar::*; -use crate::trait_::NativeArrayAccessor; -use crate::trait_::{NativeArray, NativeScalar}; +use crate::trait_::ArrayAccessor; +use crate::trait_::NativeScalar; use arrow_array::builder::Float64Builder; use arrow_array::{Float64Array, OffsetSizeTrait}; use geo::EuclideanDistance as _EuclideanDistance; diff --git a/src/algorithm/geo/euclidean_length.rs b/src/algorithm/geo/euclidean_length.rs index d881dac64..13f3ac1af 100644 --- a/src/algorithm/geo/euclidean_length.rs +++ b/src/algorithm/geo/euclidean_length.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -82,7 +82,7 @@ impl EuclideanLength for &dyn NativeArray { fn euclidean_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().euclidean_length(), @@ -140,7 +140,7 @@ impl EuclideanLength for &dyn ChunkedNativeArray { fn euclidean_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().euclidean_length(), diff --git a/src/algorithm/geo/frechet_distance.rs b/src/algorithm/geo/frechet_distance.rs index 9c270bb7e..4f432cb48 100644 --- a/src/algorithm/geo/frechet_distance.rs +++ b/src/algorithm/geo/frechet_distance.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::{Binary, MapChunks, Unary}; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedLineStringArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::LineStringTrait; use crate::io::geo::line_string_to_geo; @@ -56,7 +56,7 @@ impl FrechetDistance for &dyn NativeArray { fn frechet_distance(&self, rhs: &Self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match (self.data_type(), rhs.data_type()) { (LineString(_, XY), LineString(_, XY)) => FrechetDistance::frechet_distance( @@ -86,7 +86,7 @@ impl FrechetDistance for &dyn ChunkedNativeArray { fn frechet_distance(&self, rhs: &Self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match (self.data_type(), rhs.data_type()) { (LineString(_, XY), LineString(_, XY)) => FrechetDistance::frechet_distance( @@ -150,7 +150,7 @@ impl> FrechetDistanceLineString for &dyn NativeAr fn frechet_distance(&self, rhs: &G) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { LineString(_, XY) => { @@ -170,7 +170,7 @@ impl> FrechetDistanceLineString for &dyn ChunkedN fn frechet_distance(&self, rhs: &G) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let rhs = line_string_to_geo(rhs); let result = match self.data_type() { diff --git a/src/algorithm/geo/geodesic_area.rs b/src/algorithm/geo/geodesic_area.rs index 168b25694..4ef63b343 100644 --- a/src/algorithm/geo/geodesic_area.rs +++ b/src/algorithm/geo/geodesic_area.rs @@ -1,9 +1,9 @@ use crate::algorithm::geo::utils::zeroes; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::builder::Float64Builder; use arrow_array::{Float64Array, OffsetSizeTrait}; @@ -327,7 +327,6 @@ iter_geo_impl!(PolygonArray); iter_geo_impl!(MultiPolygonArray); iter_geo_impl!(MixedGeometryArray); iter_geo_impl!(GeometryCollectionArray); -iter_geo_impl!(WKBArray); impl GeodesicArea for &dyn NativeArray { type OutputSingle = Result; @@ -335,7 +334,7 @@ impl GeodesicArea for &dyn NativeArray { fn geodesic_area_signed(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_area_signed(), @@ -364,7 +363,7 @@ impl GeodesicArea for &dyn NativeArray { fn geodesic_area_unsigned(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_area_unsigned(), @@ -395,7 +394,7 @@ impl GeodesicArea for &dyn NativeArray { fn geodesic_perimeter(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter(), @@ -424,7 +423,7 @@ impl GeodesicArea for &dyn NativeArray { fn geodesic_perimeter_area_signed(&self) -> Self::OutputDouble { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter_area_signed(), @@ -467,7 +466,7 @@ impl GeodesicArea for &dyn NativeArray { fn geodesic_perimeter_area_unsigned(&self) -> Self::OutputDouble { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter_area_unsigned(), @@ -557,7 +556,7 @@ impl GeodesicArea for &dyn ChunkedNativeArray { fn geodesic_area_signed(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_area_signed(), @@ -585,7 +584,7 @@ impl GeodesicArea for &dyn ChunkedNativeArray { fn geodesic_area_unsigned(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_area_unsigned(), @@ -615,7 +614,7 @@ impl GeodesicArea for &dyn ChunkedNativeArray { fn geodesic_perimeter(&self) -> Self::OutputSingle { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter(), @@ -643,7 +642,7 @@ impl GeodesicArea for &dyn ChunkedNativeArray { fn geodesic_perimeter_area_signed(&self) -> Self::OutputDouble { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter_area_signed(), @@ -685,7 +684,7 @@ impl GeodesicArea for &dyn ChunkedNativeArray { fn geodesic_perimeter_area_unsigned(&self) -> Self::OutputDouble { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_perimeter_area_unsigned(), diff --git a/src/algorithm/geo/geodesic_length.rs b/src/algorithm/geo/geodesic_length.rs index 56c460e75..541678bfc 100644 --- a/src/algorithm/geo/geodesic_length.rs +++ b/src/algorithm/geo/geodesic_length.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -102,7 +102,7 @@ impl GeodesicLength for &dyn NativeArray { fn geodesic_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_length(), @@ -158,7 +158,7 @@ impl GeodesicLength for &dyn ChunkedNativeArray { fn geodesic_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().geodesic_length(), diff --git a/src/algorithm/geo/haversine_length.rs b/src/algorithm/geo/haversine_length.rs index c54fb2f04..10c67d505 100644 --- a/src/algorithm/geo/haversine_length.rs +++ b/src/algorithm/geo/haversine_length.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -96,7 +96,7 @@ impl HaversineLength for &dyn NativeArray { fn haversine_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().haversine_length(), @@ -154,7 +154,7 @@ impl HaversineLength for &dyn ChunkedNativeArray { fn haversine_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().haversine_length(), diff --git a/src/algorithm/geo/line_interpolate_point.rs b/src/algorithm/geo/line_interpolate_point.rs index 23b977d27..4e43651a8 100644 --- a/src/algorithm/geo/line_interpolate_point.rs +++ b/src/algorithm/geo/line_interpolate_point.rs @@ -2,9 +2,9 @@ use crate::algorithm::native::MapChunks; use crate::array::LineStringArray; use crate::array::*; use crate::chunked_array::{ChunkedLineStringArray, ChunkedNativeArray, ChunkedPointArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::{Float64Array, OffsetSizeTrait}; use geo::LineInterpolatePoint as _LineInterpolatePoint; @@ -71,7 +71,7 @@ impl LineInterpolatePoint<&Float64Array> for &dyn NativeArray { fn line_interpolate_point(&self, fraction: &Float64Array) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { LineString(_, XY) => Ok(self.as_line_string::<2>().line_interpolate_point(fraction)), @@ -98,7 +98,7 @@ impl LineInterpolatePoint<&[Float64Array]> for &dyn ChunkedNativeArray { fn line_interpolate_point(&self, fraction: &[Float64Array]) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { LineString(_, XY) => Ok(self.as_line_string::<2>().line_interpolate_point(fraction)), @@ -137,7 +137,7 @@ impl LineInterpolatePoint for &dyn NativeArray { fn line_interpolate_point(&self, fraction: f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { LineString(_, XY) => Ok(self.as_line_string::<2>().line_interpolate_point(fraction)), @@ -162,7 +162,7 @@ impl LineInterpolatePoint for &dyn ChunkedNativeArray { fn line_interpolate_point(&self, fraction: f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { LineString(_, XY) => Ok(self.as_line_string::<2>().line_interpolate_point(fraction)), diff --git a/src/algorithm/geo/line_locate_point.rs b/src/algorithm/geo/line_locate_point.rs index b4ff25ba8..f213c5f0a 100644 --- a/src/algorithm/geo/line_locate_point.rs +++ b/src/algorithm/geo/line_locate_point.rs @@ -1,12 +1,12 @@ use crate::algorithm::native::MapChunks; use crate::array::{AsChunkedNativeArray, AsNativeArray, LineStringArray, PointArray}; use crate::chunked_array::{ChunkedArray, ChunkedLineStringArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::PointTrait; use crate::io::geo::point_to_geo; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::{ArrayBase, NativeArray}; use arrow_array::builder::Float64Builder; use arrow_array::{Float64Array, OffsetSizeTrait}; use geo::LineLocatePoint as _LineLocatePoint; @@ -53,7 +53,7 @@ impl LineLocatePoint<&dyn NativeArray> for &dyn NativeArray { fn line_locate_point(&self, rhs: &dyn NativeArray) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match (self.data_type(), rhs.data_type()) { (LineString(_, XY), Point(_, XY)) => { @@ -85,7 +85,7 @@ impl LineLocatePoint<&dyn ChunkedNativeArray> for &dyn ChunkedNativeArray { fn line_locate_point(&self, rhs: &dyn ChunkedNativeArray) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match (self.data_type(), rhs.data_type()) { (LineString(_, XY), Point(_, XY)) => LineLocatePoint::line_locate_point( @@ -137,7 +137,7 @@ impl> LineLocatePointScalar for &dyn NativeArray { fn line_locate_point(&self, rhs: G) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { LineString(_, XY) => { @@ -169,7 +169,7 @@ impl> LineLocatePointScalar for &dyn ChunkedNativeArra fn line_locate_point(&self, rhs: G) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { LineString(_, XY) => { diff --git a/src/algorithm/geo/minimum_rotated_rect.rs b/src/algorithm/geo/minimum_rotated_rect.rs index 68d271d17..6b16385df 100644 --- a/src/algorithm/geo/minimum_rotated_rect.rs +++ b/src/algorithm/geo/minimum_rotated_rect.rs @@ -1,9 +1,9 @@ use crate::array::polygon::PolygonCapacity; use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray, ChunkedPolygonArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::MinimumRotatedRect as _MinimumRotatedRect; @@ -113,7 +113,7 @@ impl MinimumRotatedRect for &dyn NativeArray { fn minimum_rotated_rect(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().minimum_rotated_rect(), @@ -155,7 +155,7 @@ impl MinimumRotatedRect for &dyn ChunkedNativeArray { fn minimum_rotated_rect(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().minimum_rotated_rect(), diff --git a/src/algorithm/geo/remove_repeated_points.rs b/src/algorithm/geo/remove_repeated_points.rs index fd800af6e..b2457b398 100644 --- a/src/algorithm/geo/remove_repeated_points.rs +++ b/src/algorithm/geo/remove_repeated_points.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::RemoveRepeatedPoints as _RemoveRepeatedPoints; @@ -77,7 +77,7 @@ impl RemoveRepeatedPoints for &dyn NativeArray { fn remove_repeated_points(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().remove_repeated_points()), @@ -147,7 +147,7 @@ impl RemoveRepeatedPoints for &dyn ChunkedNativeArray { fn remove_repeated_points(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().remove_repeated_points()), diff --git a/src/algorithm/geo/rotate.rs b/src/algorithm/geo/rotate.rs index b96a1e219..05b3068a9 100644 --- a/src/algorithm/geo/rotate.rs +++ b/src/algorithm/geo/rotate.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use crate::algorithm::geo::{AffineOps, Center, Centroid}; use crate::array::MultiPointArray; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::{Float64Array, OffsetSizeTrait}; use geo::AffineTransform; @@ -256,7 +256,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -295,7 +295,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -334,7 +334,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -377,7 +377,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -416,7 +416,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -455,7 +455,7 @@ impl Rotate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), diff --git a/src/algorithm/geo/scale.rs b/src/algorithm/geo/scale.rs index a5773bd5e..91f98a067 100644 --- a/src/algorithm/geo/scale.rs +++ b/src/algorithm/geo/scale.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use crate::algorithm::broadcasting::BroadcastablePrimitive; use crate::array::LineStringArray; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::types::Float64Type; use arrow_array::OffsetSizeTrait; @@ -239,7 +239,7 @@ impl Scale for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -286,7 +286,7 @@ impl Scale for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), diff --git a/src/algorithm/geo/simplify.rs b/src/algorithm/geo/simplify.rs index c0acfef54..8ce23217d 100644 --- a/src/algorithm/geo/simplify.rs +++ b/src/algorithm/geo/simplify.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::Simplify as _Simplify; @@ -29,7 +29,7 @@ pub trait Simplify { /// ``` /// use geoarrow::algorithm::geo::Simplify; /// use geoarrow::array::LineStringArray; - /// use geoarrow::trait_::NativeArrayAccessor; + /// use geoarrow::trait_::ArrayAccessor; /// use geo::line_string; /// /// let line_string = line_string![ @@ -109,7 +109,7 @@ impl Simplify for &dyn NativeArray { fn simplify(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify(epsilon)), @@ -175,7 +175,7 @@ impl Simplify for &dyn ChunkedNativeArray { fn simplify(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify(epsilon)), @@ -209,7 +209,7 @@ impl Simplify for &dyn ChunkedNativeArray { mod tests { use super::*; use crate::array::{LineStringArray, PolygonArray}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geo::{line_string, polygon}; #[test] diff --git a/src/algorithm/geo/simplify_vw.rs b/src/algorithm/geo/simplify_vw.rs index d21eb8c35..5418de196 100644 --- a/src/algorithm/geo/simplify_vw.rs +++ b/src/algorithm/geo/simplify_vw.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::SimplifyVw as _SimplifyVw; @@ -28,7 +28,7 @@ pub trait SimplifyVw { /// ``` /// use geoarrow::algorithm::geo::SimplifyVw; /// use geoarrow::array::LineStringArray; - /// use geoarrow::trait_::NativeArrayAccessor; + /// use geoarrow::trait_::ArrayAccessor; /// use geo::line_string; /// /// let line_string = line_string![ @@ -107,7 +107,7 @@ impl SimplifyVw for &dyn NativeArray { fn simplify_vw(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify_vw(epsilon)), @@ -179,7 +179,7 @@ impl SimplifyVw for &dyn ChunkedNativeArray { fn simplify_vw(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify_vw(epsilon)), diff --git a/src/algorithm/geo/simplify_vw_preserve.rs b/src/algorithm/geo/simplify_vw_preserve.rs index dae91a169..4d237cac1 100644 --- a/src/algorithm/geo/simplify_vw_preserve.rs +++ b/src/algorithm/geo/simplify_vw_preserve.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo::SimplifyVwPreserve as _SimplifyVwPreserve; @@ -101,7 +101,7 @@ impl SimplifyVwPreserve for &dyn NativeArray { fn simplify_vw_preserve(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify_vw_preserve(epsilon)), @@ -182,7 +182,7 @@ impl SimplifyVwPreserve for &dyn ChunkedNativeArray { fn simplify_vw_preserve(&self, epsilon: &f64) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().simplify_vw_preserve(epsilon)), diff --git a/src/algorithm/geo/skew.rs b/src/algorithm/geo/skew.rs index 6444d89f7..7901d0c52 100644 --- a/src/algorithm/geo/skew.rs +++ b/src/algorithm/geo/skew.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use crate::algorithm::broadcasting::BroadcastablePrimitive; use crate::array::LineStringArray; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::types::Float64Type; use arrow_array::OffsetSizeTrait; @@ -265,7 +265,7 @@ impl Skew for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), @@ -312,7 +312,7 @@ impl Skew for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), diff --git a/src/algorithm/geo/translate.rs b/src/algorithm/geo/translate.rs index a5317b662..242d38f7e 100644 --- a/src/algorithm/geo/translate.rs +++ b/src/algorithm/geo/translate.rs @@ -2,9 +2,9 @@ use std::sync::Arc; use crate::algorithm::broadcasting::BroadcastablePrimitive; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::types::Float64Type; use arrow_array::OffsetSizeTrait; @@ -140,7 +140,7 @@ impl Translate for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => impl_method!(as_point), diff --git a/src/algorithm/geo/vincenty_length.rs b/src/algorithm/geo/vincenty_length.rs index 41703e9a6..eec334bf2 100644 --- a/src/algorithm/geo/vincenty_length.rs +++ b/src/algorithm/geo/vincenty_length.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -95,7 +95,7 @@ impl VincentyLength for &dyn NativeArray { fn vincenty_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().vincenty_length(), @@ -150,7 +150,7 @@ impl VincentyLength for &dyn ChunkedNativeArray { fn vincenty_length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().vincenty_length(), diff --git a/src/algorithm/geo/within.rs b/src/algorithm/geo/within.rs index 7f7af6203..3f8522220 100644 --- a/src/algorithm/geo/within.rs +++ b/src/algorithm/geo/within.rs @@ -1,6 +1,6 @@ use crate::array::*; use crate::scalar::*; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::trait_::NativeScalar; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; diff --git a/src/algorithm/geo_index/rtree.rs b/src/algorithm/geo_index/rtree.rs index 2c85e15ad..0047ea63a 100644 --- a/src/algorithm/geo_index/rtree.rs +++ b/src/algorithm/geo_index/rtree.rs @@ -5,10 +5,10 @@ use crate::algorithm::native::bounding_rect::{ }; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::PointTrait; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use geo_index::rtree::sort::HilbertSort; @@ -92,7 +92,7 @@ impl RTree for &dyn NativeArray { fn create_rtree_with_node_size(&self, node_size: usize) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().create_rtree_with_node_size(node_size), @@ -155,7 +155,7 @@ impl RTree for &dyn ChunkedNativeArray { fn create_rtree_with_node_size(&self, node_size: usize) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result = match self.data_type() { Point(_, XY) => self.as_point::<2>().create_rtree_with_node_size(node_size), diff --git a/src/algorithm/geos/area.rs b/src/algorithm/geos/area.rs index 388097030..94c973007 100644 --- a/src/algorithm/geos/area.rs +++ b/src/algorithm/geos/area.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -65,7 +65,7 @@ impl Area for &dyn NativeArray { fn area(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().area(), diff --git a/src/algorithm/geos/buffer.rs b/src/algorithm/geos/buffer.rs index ee164d0e8..fe4d6cf95 100644 --- a/src/algorithm/geos/buffer.rs +++ b/src/algorithm/geos/buffer.rs @@ -1,7 +1,7 @@ use crate::array::{PointArray, PolygonArray, PolygonBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSPolygon; -use crate::trait_::{NativeArrayAccessor, NativeScalar}; +use crate::trait_::{ArrayAccessor, NativeScalar}; use arrow_array::OffsetSizeTrait; use geos::{BufferParams, Geom}; diff --git a/src/algorithm/geos/is_ring.rs b/src/algorithm/geos/is_ring.rs index 6a8c62e65..75aaca5a5 100644 --- a/src/algorithm/geos/is_ring.rs +++ b/src/algorithm/geos/is_ring.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::trait_::NativeScalar; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; @@ -64,14 +64,13 @@ iter_geos_impl!(PolygonArray); iter_geos_impl!(MultiPolygonArray); iter_geos_impl!(MixedGeometryArray); iter_geos_impl!(GeometryCollectionArray); -iter_geos_impl!(WKBArray); impl IsRing for &dyn NativeArray { type Output = Result; fn is_ring(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().is_ring(), diff --git a/src/algorithm/geos/is_valid.rs b/src/algorithm/geos/is_valid.rs index 72b91f963..66b95178f 100644 --- a/src/algorithm/geos/is_valid.rs +++ b/src/algorithm/geos/is_valid.rs @@ -1,8 +1,8 @@ use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::trait_::NativeScalar; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; @@ -64,14 +64,13 @@ iter_geos_impl!(PolygonArray); iter_geos_impl!(MultiPolygonArray); iter_geos_impl!(MixedGeometryArray); iter_geos_impl!(GeometryCollectionArray); -iter_geos_impl!(WKBArray); impl IsValid for &dyn NativeArray { type Output = Result; fn is_valid(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => IsValid::is_valid(self.as_point::<2>()), diff --git a/src/algorithm/geos/length.rs b/src/algorithm/geos/length.rs index 228eb64e7..3c895ed92 100644 --- a/src/algorithm/geos/length.rs +++ b/src/algorithm/geos/length.rs @@ -2,7 +2,7 @@ use crate::algorithm::geo::utils::zeroes; use crate::algorithm::native::Unary; use crate::array::*; use crate::chunked_array::{ChunkedArray, ChunkedGeometryArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -51,7 +51,7 @@ impl Length for &dyn NativeArray { fn length(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().length(), diff --git a/src/algorithm/native/binary.rs b/src/algorithm/native/binary.rs index 58bb23876..69e0b0549 100644 --- a/src/algorithm/native/binary.rs +++ b/src/algorithm/native/binary.rs @@ -7,9 +7,9 @@ use arrow_data::ArrayData; use crate::array::*; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; -pub trait Binary<'a, Rhs: NativeArrayAccessor<'a> = Self>: NativeArrayAccessor<'a> { +pub trait Binary<'a, Rhs: ArrayAccessor<'a> = Self>: ArrayAccessor<'a> { fn binary_boolean(&'a self, rhs: &'a Rhs, op: F) -> Result where F: Fn(Self::Item, Rhs::Item) -> bool, @@ -128,7 +128,6 @@ impl<'a, O: OffsetSizeTrait> Binary<'a, PointArray<2>> for MultiLineStringArray< impl<'a, O: OffsetSizeTrait> Binary<'a, PointArray<2>> for MultiPolygonArray {} impl<'a, O: OffsetSizeTrait> Binary<'a, PointArray<2>> for MixedGeometryArray {} impl<'a, O: OffsetSizeTrait> Binary<'a, PointArray<2>> for GeometryCollectionArray {} -impl<'a, O: OffsetSizeTrait> Binary<'a, PointArray<2>> for WKBArray {} // Implementations on LineStringArray impl<'a, O: OffsetSizeTrait> Binary<'a, LineStringArray> for PointArray<2> {} @@ -161,10 +160,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, LineStringArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, LineStringArray> - for WKBArray -{ -} // Implementations on PolygonArray impl<'a, O: OffsetSizeTrait> Binary<'a, PolygonArray> for PointArray<2> {} @@ -197,10 +192,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, PolygonArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, PolygonArray> - for WKBArray -{ -} // Implementations on MultiPointArray impl<'a, O: OffsetSizeTrait> Binary<'a, MultiPointArray> for PointArray<2> {} @@ -233,10 +224,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiPointArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiPointArray> - for WKBArray -{ -} // Implementations on MultiLineStringArray impl<'a, O: OffsetSizeTrait> Binary<'a, MultiLineStringArray> for PointArray<2> {} @@ -269,10 +256,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiLineStringArr for GeometryCollectionArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiLineStringArray> - for WKBArray -{ -} // Implementations on MultiPolygonArray impl<'a, O: OffsetSizeTrait> Binary<'a, MultiPolygonArray> for PointArray<2> {} @@ -305,10 +288,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiPolygonArray< for GeometryCollectionArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MultiPolygonArray> - for WKBArray -{ -} // Implementations on MixedGeometryArray impl<'a, O: OffsetSizeTrait> Binary<'a, MixedGeometryArray> for PointArray<2> {} @@ -341,10 +320,6 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MixedGeometryArray for GeometryCollectionArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, MixedGeometryArray> - for WKBArray -{ -} // Implementations on GeometryCollectionArray impl<'a, O: OffsetSizeTrait> Binary<'a, GeometryCollectionArray> for PointArray<2> {} @@ -377,40 +352,3 @@ impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, GeometryCollection for GeometryCollectionArray { } -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, GeometryCollectionArray> - for WKBArray -{ -} - -// Implementations on WKBArray -impl<'a, O: OffsetSizeTrait> Binary<'a, WKBArray> for PointArray<2> {} -impl<'a, O: OffsetSizeTrait> Binary<'a, WKBArray> for RectArray<2> {} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for LineStringArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for PolygonArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for MultiPointArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for MultiLineStringArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for MultiPolygonArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for MixedGeometryArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> - for GeometryCollectionArray -{ -} -impl<'a, O1: OffsetSizeTrait, O2: OffsetSizeTrait> Binary<'a, WKBArray> for WKBArray {} diff --git a/src/algorithm/native/cast.rs b/src/algorithm/native/cast.rs index 5aad5f013..8b1f62c8a 100644 --- a/src/algorithm/native/cast.rs +++ b/src/algorithm/native/cast.rs @@ -11,7 +11,7 @@ use arrow_array::OffsetSizeTrait; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::NativeArray; @@ -30,13 +30,13 @@ impl Default for CastOptions { /// Note: not currently used and outdated #[allow(dead_code)] -fn can_cast_types(from_type: &GeoDataType, to_type: &GeoDataType) -> bool { +fn can_cast_types(from_type: &NativeType, to_type: &NativeType) -> bool { if from_type == to_type { return true; } use Dimension::*; - use GeoDataType::*; + use NativeType::*; match (from_type, to_type) { (Point(_, XY), Point(_, XY) | MultiPoint(_, XY)) => true, @@ -53,16 +53,16 @@ pub trait Cast { type Output; /// Note: **does not currently implement dimension casts** - fn cast(&self, to_type: &GeoDataType) -> Self::Output; + fn cast(&self, to_type: &NativeType) -> Self::Output; } impl Cast for PointArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Point(_, _) => Ok(Arc::new(array)), MultiPoint(_, _) => Ok(Arc::new(MultiPointArray::::from(array))), @@ -85,10 +85,10 @@ impl Cast for PointArray { impl Cast for LineStringArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { LineString(_, _) => { @@ -169,10 +169,10 @@ impl Cast for LineStringArray { impl Cast for PolygonArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Polygon(_, _) => { @@ -253,10 +253,10 @@ impl Cast for PolygonArray { impl Cast for MultiPointArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Point(_, _) => Ok(Arc::new(PointArray::::try_from(array)?)), @@ -320,10 +320,10 @@ impl Cast for MultiPointArray { impl Cast for MultiLineStringArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { LineString(_, _) => { @@ -390,10 +390,10 @@ impl Cast for MultiLineStringArray { impl Cast for MultiPolygonArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Polygon(_, _) => { @@ -460,10 +460,10 @@ impl Cast for MultiPolygonArray { impl Cast for MixedGeometryArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Point(_, _) => Ok(Arc::new(PointArray::try_from(array)?)), @@ -599,10 +599,10 @@ impl Cast for MixedGeometryArray { impl Cast for GeometryCollectionArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { - use GeoDataType::*; + fn cast(&self, to_type: &NativeType) -> Self::Output { + use NativeType::*; - let array = self.to_coord_type(to_type.coord_type().unwrap()); + let array = self.to_coord_type(to_type.coord_type()); match to_type { Point(_, _) => Ok(Arc::new(PointArray::try_from(array)?)), @@ -738,14 +738,14 @@ impl Cast for GeometryCollectionArray impl Cast for &dyn NativeArray { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { + fn cast(&self, to_type: &NativeType) -> Self::Output { // TODO: not working :/ // if self.data_type() == to_type { // return Ok(Arc::new(self.to_owned())); // } use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_ref().as_point::<2>().cast(to_type), @@ -800,7 +800,7 @@ macro_rules! impl_chunked_cast_non_generic { impl Cast for $chunked_array { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { + fn cast(&self, to_type: &NativeType) -> Self::Output { macro_rules! impl_cast { ($method:ident) => { Arc::new(ChunkedGeometryArray::new( @@ -830,7 +830,7 @@ macro_rules! impl_chunked_cast_non_generic { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match to_type { Point(_, XY) => impl_cast!(as_point, 2), @@ -871,8 +871,6 @@ macro_rules! impl_chunked_cast_non_generic { LargeGeometryCollection(_, XYZ) => { impl_cast!(as_large_geometry_collection, 3) } - WKB => impl_cast!(as_wkb), - LargeWKB => impl_cast!(as_large_wkb), Rect(XY) => impl_cast!(as_rect, 2), Rect(XYZ) => impl_cast!(as_rect, 3), }; @@ -887,7 +885,7 @@ macro_rules! impl_chunked_cast_generic { impl Cast for $chunked_array { type Output = Result>; - fn cast(&self, to_type: &GeoDataType) -> Self::Output { + fn cast(&self, to_type: &NativeType) -> Self::Output { macro_rules! impl_cast { ($method:ident) => { Arc::new(ChunkedGeometryArray::new( @@ -917,7 +915,7 @@ macro_rules! impl_chunked_cast_generic { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match to_type { Point(_, XY) => impl_cast!(as_point, 2), @@ -958,8 +956,6 @@ macro_rules! impl_chunked_cast_generic { LargeGeometryCollection(_, XYZ) => { impl_cast!(as_large_geometry_collection, 3) } - WKB => impl_cast!(as_wkb), - LargeWKB => impl_cast!(as_large_wkb), Rect(XY) => impl_cast!(as_rect, 2), Rect(XYZ) => impl_cast!(as_rect, 3), }; diff --git a/src/algorithm/native/concatenate.rs b/src/algorithm/native/concatenate.rs index fcb8c635b..df1a1f0d0 100644 --- a/src/algorithm/native/concatenate.rs +++ b/src/algorithm/native/concatenate.rs @@ -3,7 +3,7 @@ use arrow_array::OffsetSizeTrait; use crate::array::*; use crate::chunked_array::*; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; pub trait Concatenate: Sized { type Output; diff --git a/src/algorithm/native/downcast.rs b/src/algorithm/native/downcast.rs index 7e197be2d..1167a751f 100644 --- a/src/algorithm/native/downcast.rs +++ b/src/algorithm/native/downcast.rs @@ -11,7 +11,7 @@ use crate::array::offset_builder::OffsetsBuilder; use crate::array::util::OffsetBufferUtils; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; use crate::schema::GeoSchemaExt; use crate::table::Table; @@ -21,7 +21,7 @@ pub trait Downcast { type Output; /// The data type that downcasting would result in. - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType; + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType; /// If possible, convert this array to a simpler and/or smaller data type /// @@ -41,7 +41,7 @@ pub trait Downcast { impl Downcast for PointArray<2> { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { self.data_type() } @@ -92,14 +92,14 @@ pub(crate) fn can_downcast_multi(buffer: &OffsetBuffer) - impl Downcast for LineStringArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { match self.data_type() { - GeoDataType::LineString(ct, dim) => GeoDataType::LineString(ct, dim), - GeoDataType::LargeLineString(ct, dim) => { + NativeType::LineString(ct, dim) => NativeType::LineString(ct, dim), + NativeType::LargeLineString(ct, dim) => { if small_offsets && can_downcast_offsets_i32(&self.geom_offsets) { - GeoDataType::LineString(ct, dim) + NativeType::LineString(ct, dim) } else { - GeoDataType::LargeLineString(ct, dim) + NativeType::LargeLineString(ct, dim) } } _ => unreachable!(), @@ -109,16 +109,16 @@ impl Downcast for LineStringArray { fn downcast(&self, small_offsets: bool) -> Self::Output { match (self.data_type(), self.downcasted_data_type(small_offsets)) { ( - GeoDataType::LineString(_, Dimension::XY), - GeoDataType::LineString(_, Dimension::XY), + NativeType::LineString(_, Dimension::XY), + NativeType::LineString(_, Dimension::XY), ) | ( - GeoDataType::LargeLineString(_, Dimension::XY), - GeoDataType::LargeLineString(_, Dimension::XY), + NativeType::LargeLineString(_, Dimension::XY), + NativeType::LargeLineString(_, Dimension::XY), ) => Arc::new(self.clone()), ( - GeoDataType::LargeLineString(_, Dimension::XY), - GeoDataType::LineString(_, Dimension::XY), + NativeType::LargeLineString(_, Dimension::XY), + NativeType::LineString(_, Dimension::XY), ) => todo!(), _ => unreachable!(), } @@ -128,14 +128,14 @@ impl Downcast for LineStringArray { impl Downcast for PolygonArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { match self.data_type() { - GeoDataType::Polygon(ct, dim) => GeoDataType::Polygon(ct, dim), - GeoDataType::LargePolygon(ct, dim) => { + NativeType::Polygon(ct, dim) => NativeType::Polygon(ct, dim), + NativeType::LargePolygon(ct, dim) => { if small_offsets && can_downcast_offsets_i32(&self.ring_offsets) { - GeoDataType::Polygon(ct, dim) + NativeType::Polygon(ct, dim) } else { - GeoDataType::LargePolygon(ct, dim) + NativeType::LargePolygon(ct, dim) } } _ => unreachable!(), @@ -150,23 +150,23 @@ impl Downcast for PolygonArray { impl Downcast for MultiPointArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { match self.data_type() { - GeoDataType::MultiPoint(ct, dim) => { + NativeType::MultiPoint(ct, dim) => { if can_downcast_multi(&self.geom_offsets) { - GeoDataType::Point(ct, dim) + NativeType::Point(ct, dim) } else { - GeoDataType::MultiPoint(ct, dim) + NativeType::MultiPoint(ct, dim) } } - GeoDataType::LargeMultiPoint(ct, dim) => { + NativeType::LargeMultiPoint(ct, dim) => { match ( can_downcast_multi(&self.geom_offsets), small_offsets && can_downcast_offsets_i32(&self.geom_offsets), ) { - (true, _) => GeoDataType::Point(ct, dim), - (false, true) => GeoDataType::MultiPoint(ct, dim), - (false, false) => GeoDataType::LargeMultiPoint(ct, dim), + (true, _) => NativeType::Point(ct, dim), + (false, true) => NativeType::MultiPoint(ct, dim), + (false, false) => NativeType::LargeMultiPoint(ct, dim), } } _ => unreachable!(), @@ -189,24 +189,24 @@ impl Downcast for MultiPointArray { impl Downcast for MultiLineStringArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { match self.data_type() { - GeoDataType::MultiLineString(ct, dim) => { + NativeType::MultiLineString(ct, dim) => { if can_downcast_multi(&self.geom_offsets) { - GeoDataType::LineString(ct, dim) + NativeType::LineString(ct, dim) } else { - GeoDataType::MultiLineString(ct, dim) + NativeType::MultiLineString(ct, dim) } } - GeoDataType::LargeMultiLineString(ct, dim) => { + NativeType::LargeMultiLineString(ct, dim) => { match ( can_downcast_multi(&self.geom_offsets), small_offsets && can_downcast_offsets_i32(&self.ring_offsets), ) { - (true, true) => GeoDataType::LineString(ct, dim), - (true, false) => GeoDataType::LargeLineString(ct, dim), - (false, true) => GeoDataType::MultiLineString(ct, dim), - (false, false) => GeoDataType::LargeMultiLineString(ct, dim), + (true, true) => NativeType::LineString(ct, dim), + (true, false) => NativeType::LargeLineString(ct, dim), + (false, true) => NativeType::MultiLineString(ct, dim), + (false, false) => NativeType::LargeMultiLineString(ct, dim), } } _ => unreachable!(), @@ -230,24 +230,24 @@ impl Downcast for MultiLineStringArray { impl Downcast for MultiPolygonArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { match self.data_type() { - GeoDataType::MultiPolygon(ct, dim) => { + NativeType::MultiPolygon(ct, dim) => { if can_downcast_multi(&self.geom_offsets) { - GeoDataType::Polygon(ct, dim) + NativeType::Polygon(ct, dim) } else { - GeoDataType::MultiPolygon(ct, dim) + NativeType::MultiPolygon(ct, dim) } } - GeoDataType::LargeMultiPolygon(ct, dim) => { + NativeType::LargeMultiPolygon(ct, dim) => { match ( can_downcast_multi(&self.geom_offsets), small_offsets && can_downcast_offsets_i32(&self.ring_offsets), ) { - (true, true) => GeoDataType::Polygon(ct, dim), - (true, false) => GeoDataType::LargePolygon(ct, dim), - (false, true) => GeoDataType::MultiPolygon(ct, dim), - (false, false) => GeoDataType::LargeMultiPolygon(ct, dim), + (true, true) => NativeType::Polygon(ct, dim), + (true, false) => NativeType::LargePolygon(ct, dim), + (false, true) => NativeType::MultiPolygon(ct, dim), + (false, false) => NativeType::LargeMultiPolygon(ct, dim), } } _ => unreachable!(), @@ -272,7 +272,7 @@ impl Downcast for MultiPolygonArray { impl Downcast for MixedGeometryArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { let coord_type = self.coord_type(); if self.has_points() @@ -282,7 +282,7 @@ impl Downcast for MixedGeometryArray { && !self.has_multi_line_strings() && !self.has_multi_polygons() { - return GeoDataType::Point(coord_type, Dimension::XY); + return NativeType::Point(coord_type, Dimension::XY); } if !self.has_points() @@ -407,7 +407,7 @@ impl Downcast for MixedGeometryArray { impl Downcast for GeometryCollectionArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { todo!() } fn downcast(&self, small_offsets: bool) -> Self::Output { @@ -424,7 +424,7 @@ impl Downcast for GeometryCollectionArray { impl Downcast for RectArray<2> { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { self.data_type() } fn downcast(&self, small_offsets: bool) -> Self::Output { @@ -435,9 +435,9 @@ impl Downcast for RectArray<2> { impl Downcast for &dyn NativeArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().downcasted_data_type(small_offsets), @@ -480,16 +480,13 @@ impl Downcast for &dyn NativeArray { .as_large_geometry_collection::<2>() .downcasted_data_type(small_offsets), Rect(XY) => self.as_rect::<2>().downcasted_data_type(small_offsets), - // TODO: downcast largewkb to wkb - WKB => self.data_type(), - LargeWKB => self.data_type(), _ => todo!("3d support"), } } fn downcast(&self, small_offsets: bool) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().downcast(small_offsets), @@ -512,15 +509,13 @@ impl Downcast for &dyn NativeArray { .as_large_geometry_collection::<2>() .downcast(small_offsets), Rect(XY) => self.as_rect::<2>().downcast(small_offsets), - WKB => Arc::new(self.as_wkb().clone()), - LargeWKB => Arc::new(self.as_large_wkb().clone()), _ => todo!("3d support"), } } } /// Given a set of types, return a single type that the result should be casted to -fn resolve_types(types: &HashSet) -> GeoDataType { +fn resolve_types(types: &HashSet) -> NativeType { if types.is_empty() { panic!("empty types"); } else if types.len() == 1 { @@ -534,29 +529,29 @@ fn resolve_types(types: &HashSet) -> GeoDataType { if extension_name_set.contains("geoarrow.point") && extension_name_set.contains("geoarrow.multipoint") { - GeoDataType::MultiPoint(Default::default(), Dimension::XY) + NativeType::MultiPoint(Default::default(), Dimension::XY) } else if extension_name_set.contains("geoarrow.linestring") && extension_name_set.contains("geoarrow.multilinestring") { - GeoDataType::MultiLineString(Default::default(), Dimension::XY) + NativeType::MultiLineString(Default::default(), Dimension::XY) } else if extension_name_set.contains("geoarrow.polygon") && extension_name_set.contains("geoarrow.multipolygon") { - GeoDataType::MultiPolygon(Default::default(), Dimension::XY) + NativeType::MultiPolygon(Default::default(), Dimension::XY) } else if extension_name_set.contains("geoarrow.geometrycollection") { - GeoDataType::GeometryCollection(Default::default(), Dimension::XY) + NativeType::GeometryCollection(Default::default(), Dimension::XY) } else { - GeoDataType::Mixed(Default::default(), Dimension::XY) + NativeType::Mixed(Default::default(), Dimension::XY) } } else { - GeoDataType::Mixed(Default::default(), Dimension::XY) + NativeType::Mixed(Default::default(), Dimension::XY) } } impl Downcast for ChunkedPointArray<2> { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { self.data_type() } fn downcast(&self, small_offsets: bool) -> Self::Output { @@ -569,7 +564,7 @@ macro_rules! impl_chunked_downcast { impl Downcast for $chunked_array { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { let mut types = HashSet::new(); self.chunks.iter().for_each(|chunk| { types.insert(chunk.downcasted_data_type(small_offsets)); @@ -600,7 +595,7 @@ impl_chunked_downcast!(ChunkedGeometryCollectionArray); impl Downcast for ChunkedRectArray<2> { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { self.data_type() } fn downcast(&self, small_offsets: bool) -> Self::Output { @@ -611,9 +606,9 @@ impl Downcast for ChunkedRectArray<2> { impl Downcast for &dyn ChunkedNativeArray { type Output = Arc; - fn downcasted_data_type(&self, small_offsets: bool) -> GeoDataType { + fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().downcasted_data_type(small_offsets), @@ -662,7 +657,7 @@ impl Downcast for &dyn ChunkedNativeArray { fn downcast(&self, small_offsets: bool) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().downcast(small_offsets), @@ -685,8 +680,6 @@ impl Downcast for &dyn ChunkedNativeArray { .as_large_geometry_collection::<2>() .downcast(small_offsets), Rect(XY) => self.as_rect::<2>().downcast(small_offsets), - WKB => Arc::new(self.as_wkb().clone()), - LargeWKB => Arc::new(self.as_large_wkb().clone()), _ => todo!("3d support"), } } diff --git a/src/algorithm/native/explode.rs b/src/algorithm/native/explode.rs index cc82bb7f6..6ec550f1f 100644 --- a/src/algorithm/native/explode.rs +++ b/src/algorithm/native/explode.rs @@ -9,7 +9,7 @@ use crate::array::*; use crate::chunked_array::{ from_geoarrow_chunks, ChunkedArray, ChunkedGeometryArray, ChunkedNativeArray, }; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::table::Table; use crate::NativeArray; @@ -139,7 +139,7 @@ impl Explode for &dyn NativeArray { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: (Arc, Option) = match self.data_type() { Point(_, XY) => call_explode!(as_point), @@ -196,7 +196,7 @@ impl Explode for &dyn ChunkedNativeArray { fn explode(&self) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().explode(), @@ -288,7 +288,7 @@ impl ExplodeTable for Table { mod test { use super::*; use crate::test::multipoint; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; #[test] fn explode_multi_point() { diff --git a/src/algorithm/native/map_coords.rs b/src/algorithm/native/map_coords.rs index a585991db..6d78ddbc3 100644 --- a/src/algorithm/native/map_coords.rs +++ b/src/algorithm/native/map_coords.rs @@ -4,14 +4,14 @@ use arrow_array::OffsetSizeTrait; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{ GeometryCollectionTrait, GeometryTrait, GeometryType, LineStringTrait, MultiLineStringTrait, MultiPointTrait, MultiPolygonTrait, PolygonTrait, RectTrait, }; use crate::scalar::*; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; pub trait MapCoords { @@ -447,7 +447,7 @@ impl MapCoords for &dyn NativeArray { GeoArrowError: From, { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().try_map_coords(map_op)?), @@ -623,7 +623,7 @@ impl MapCoords for &dyn ChunkedNativeArray { GeoArrowError: From, { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().try_map_coords(map_op)?), diff --git a/src/algorithm/native/take.rs b/src/algorithm/native/take.rs index 95a06c4f7..4a783ad83 100644 --- a/src/algorithm/native/take.rs +++ b/src/algorithm/native/take.rs @@ -3,9 +3,9 @@ use std::sync::Arc; use crate::array::*; use crate::chunked_array::ChunkedGeometryArray; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::{OffsetSizeTrait, UInt32Array}; use arrow_buffer::ArrowNativeType; @@ -214,7 +214,7 @@ impl Take for &dyn NativeArray { fn take(&self, indices: &UInt32Array) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().take(indices)), @@ -245,7 +245,7 @@ impl Take for &dyn NativeArray { fn take_range(&self, range: &Range) -> Self::Output { use Dimension::*; - use GeoDataType::*; + use NativeType::*; let result: Arc = match self.data_type() { Point(_, XY) => Arc::new(self.as_point::<2>().take_range(range)), diff --git a/src/algorithm/native/total_bounds.rs b/src/algorithm/native/total_bounds.rs index a92f67ff0..b31d90310 100644 --- a/src/algorithm/native/total_bounds.rs +++ b/src/algorithm/native/total_bounds.rs @@ -3,8 +3,8 @@ use arrow_array::OffsetSizeTrait; use crate::algorithm::native::bounding_rect::BoundingRect; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; -use crate::trait_::NativeArrayAccessor; +use crate::datatypes::{Dimension, NativeType}; +use crate::trait_::ArrayAccessor; use crate::NativeArray; /// Computes the total bounds (extent) of the input. @@ -54,20 +54,20 @@ impl_array!(MultiPolygonArray, add_multi_polygon); impl_array!(MixedGeometryArray, add_geometry); impl_array!(GeometryCollectionArray, add_geometry_collection); -impl TotalBounds for WKBArray { - fn total_bounds(&self) -> BoundingRect { - let mut bounds = BoundingRect::new(); - for geom in self.iter().flatten() { - bounds.add_geometry(&geom.to_wkb_object()); - } - bounds - } -} +// impl TotalBounds for WKBArray { +// fn total_bounds(&self) -> BoundingRect { +// let mut bounds = BoundingRect::new(); +// for geom in self.iter().flatten() { +// bounds.add_geometry(&geom.to_wkb_object()); +// } +// bounds +// } +// } impl TotalBounds for &dyn NativeArray { fn total_bounds(&self) -> BoundingRect { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().total_bounds(), @@ -106,8 +106,8 @@ impl TotalBounds for &dyn NativeArray { self.as_large_geometry_collection::<3>().total_bounds() } Rect(XYZ) => self.as_rect::<3>().total_bounds(), - WKB => self.as_wkb().total_bounds(), - LargeWKB => self.as_large_wkb().total_bounds(), + // WKB => self.as_wkb().total_bounds(), + // LargeWKB => self.as_large_wkb().total_bounds(), } } } @@ -124,7 +124,7 @@ impl TotalBounds for ChunkedGeometryArray { impl TotalBounds for &dyn ChunkedNativeArray { fn total_bounds(&self) -> BoundingRect { use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => self.as_point::<2>().total_bounds(), @@ -163,8 +163,6 @@ impl TotalBounds for &dyn ChunkedNativeArray { self.as_large_geometry_collection::<3>().total_bounds() } Rect(XYZ) => self.as_rect::<3>().total_bounds(), - WKB => self.as_wkb().total_bounds(), - LargeWKB => self.as_large_wkb().total_bounds(), } } } diff --git a/src/algorithm/native/type_id.rs b/src/algorithm/native/type_id.rs index f7bc2b2a5..09ef52bcc 100644 --- a/src/algorithm/native/type_id.rs +++ b/src/algorithm/native/type_id.rs @@ -1,5 +1,5 @@ use crate::array::*; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow::array::Int16Builder; use arrow_array::{Int16Array, OffsetSizeTrait}; diff --git a/src/algorithm/native/unary.rs b/src/algorithm/native/unary.rs index d28a04eb9..3e43cd16e 100644 --- a/src/algorithm/native/unary.rs +++ b/src/algorithm/native/unary.rs @@ -4,9 +4,9 @@ use arrow_buffer::{BooleanBufferBuilder, BufferBuilder}; use crate::array::*; use crate::geo_traits::*; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; -pub trait Unary<'a>: NativeArrayAccessor<'a> { +pub trait Unary<'a>: ArrayAccessor<'a> { // Note: This is derived from arrow-rs here: // https://github.com/apache/arrow-rs/blob/3ed7cc61d4157263ef2ab5c2d12bc7890a5315b3/arrow-array/src/array/primitive_array.rs#L753-L767 fn unary_primitive(&'a self, op: F) -> PrimitiveArray @@ -84,7 +84,20 @@ pub trait Unary<'a>: NativeArrayAccessor<'a> { Ok(BooleanArray::new(buffer.finish(), nulls)) } +} + +impl<'a> Unary<'a> for PointArray<2> {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for LineStringArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for PolygonArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiPointArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiLineStringArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiPolygonArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for MixedGeometryArray {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for GeometryCollectionArray {} +impl<'a> Unary<'a> for RectArray<2> {} +impl<'a, O: OffsetSizeTrait> Unary<'a> for WKBArray {} +pub trait UnaryPoint<'a>: ArrayAccessor<'a> + NativeArray { fn unary_point(&'a self, op: F) -> PointArray<2> where G: PointTrait + 'a, @@ -119,13 +132,12 @@ pub trait Unary<'a>: NativeArrayAccessor<'a> { } } -impl<'a> Unary<'a> for PointArray<2> {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for LineStringArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for PolygonArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiPointArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiLineStringArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for MultiPolygonArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for MixedGeometryArray {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for GeometryCollectionArray {} -impl<'a> Unary<'a> for RectArray<2> {} -impl<'a, O: OffsetSizeTrait> Unary<'a> for WKBArray {} +impl<'a> UnaryPoint<'a> for PointArray<2> {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for LineStringArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for PolygonArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for MultiPointArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for MultiLineStringArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for MultiPolygonArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for MixedGeometryArray {} +impl<'a, O: OffsetSizeTrait> UnaryPoint<'a> for GeometryCollectionArray {} +impl<'a> UnaryPoint<'a> for RectArray<2> {} diff --git a/src/algorithm/polylabel.rs b/src/algorithm/polylabel.rs index 5f00f68ad..e7af54986 100644 --- a/src/algorithm/polylabel.rs +++ b/src/algorithm/polylabel.rs @@ -6,7 +6,7 @@ use crate::array::{AsChunkedNativeArray, AsNativeArray, PointArray, PolygonArray use crate::chunked_array::{ ChunkedGeometryArray, ChunkedNativeArray, ChunkedPointArray, ChunkedPolygonArray, }; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::trait_::NativeScalar; use crate::NativeArray; @@ -39,8 +39,8 @@ impl Polylabel for &dyn NativeArray { fn polylabel(&self, tolerance: f64) -> Self::Output { match self.data_type() { - GeoDataType::Polygon(_, Dimension::XY) => self.as_polygon::<2>().polylabel(tolerance), - GeoDataType::LargePolygon(_, Dimension::XY) => { + NativeType::Polygon(_, Dimension::XY) => self.as_polygon::<2>().polylabel(tolerance), + NativeType::LargePolygon(_, Dimension::XY) => { self.as_large_polygon::<2>().polylabel(tolerance) } _ => Err(GeoArrowError::IncorrectType("".into())), @@ -62,8 +62,8 @@ impl Polylabel for &dyn ChunkedNativeArray { fn polylabel(&self, tolerance: f64) -> Self::Output { match self.data_type() { - GeoDataType::Polygon(_, Dimension::XY) => self.as_polygon::<2>().polylabel(tolerance), - GeoDataType::LargePolygon(_, Dimension::XY) => { + NativeType::Polygon(_, Dimension::XY) => self.as_polygon::<2>().polylabel(tolerance), + NativeType::LargePolygon(_, Dimension::XY) => { self.as_large_polygon::<2>().polylabel(tolerance) } _ => Err(GeoArrowError::IncorrectType("".into())), diff --git a/src/algorithm/proj.rs b/src/algorithm/proj.rs index 00522d68b..ad071930e 100644 --- a/src/algorithm/proj.rs +++ b/src/algorithm/proj.rs @@ -2,7 +2,7 @@ use crate::array::*; use crate::error::Result; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; use proj::{Proj, Transform}; @@ -68,7 +68,7 @@ iter_geo_impl!( #[cfg(test)] mod test { - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use approx::assert_relative_eq; use super::*; diff --git a/src/algorithm/rstar.rs b/src/algorithm/rstar.rs index e0e5963e8..46115aded 100644 --- a/src/algorithm/rstar.rs +++ b/src/algorithm/rstar.rs @@ -1,7 +1,7 @@ //! Bindings to the [`rstar`] crate for dynamic R-Trees. use crate::array::*; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use arrow_array::OffsetSizeTrait; use rstar::primitives::CachedEnvelope; diff --git a/src/array/binary/array.rs b/src/array/binary/array.rs index 12a34ba62..6d5e523b1 100644 --- a/src/array/binary/array.rs +++ b/src/array/binary/array.rs @@ -4,13 +4,12 @@ use crate::array::binary::WKBCapacity; use crate::array::metadata::ArrayMetadata; use crate::array::util::{offsets_buffer_i32_to_i64, offsets_buffer_i64_to_i32}; use crate::array::{CoordType, WKBBuilder}; -use crate::datatypes::GeoDataType; +use crate::datatypes::{NativeType, SerializedType}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::GeometryTrait; use crate::scalar::WKB; // use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; -use crate::NativeArray; +use crate::trait_::{ArrayAccessor, ArrayBase, IntoArrow}; use arrow_array::OffsetSizeTrait; use arrow_array::{Array, BinaryArray, GenericBinaryArray, LargeBinaryArray}; use arrow_buffer::NullBuffer; @@ -26,7 +25,7 @@ use arrow_schema::{DataType, Field}; /// strongly-typed arrays (such as the [`PointArray`][crate::array::PointArray]) for computations. #[derive(Debug, Clone, PartialEq)] pub struct WKBArray { - pub(crate) data_type: GeoDataType, + pub(crate) data_type: SerializedType, pub(crate) metadata: Arc, pub(crate) array: GenericBinaryArray, } @@ -36,8 +35,8 @@ impl WKBArray { /// Create a new WKBArray from a BinaryArray pub fn new(array: GenericBinaryArray, metadata: Arc) -> Self { let data_type = match O::IS_LARGE { - true => GeoDataType::LargeWKB, - false => GeoDataType::WKB, + true => SerializedType::LargeWKB, + false => SerializedType::WKB, }; Self { @@ -52,14 +51,14 @@ impl WKBArray { self.len() == 0 } - /// Infer the minimal GeoDataType that this WKBArray can be casted to. + /// Infer the minimal NativeType that this WKBArray can be casted to. #[allow(dead_code)] // TODO: is this obsolete with new from_wkb approach that uses downcasting? pub(crate) fn infer_geo_data_type( &self, large_type: bool, coord_type: CoordType, - ) -> Result { + ) -> Result { use crate::io::wkb::reader::r#type::infer_geometry_type; infer_geometry_type(self.iter().flatten(), large_type, coord_type) } @@ -122,17 +121,19 @@ impl WKBArray { // validity, // )) } + + pub fn with_metadata(&self, metadata: Arc) -> Self { + let mut arr = self.clone(); + arr.metadata = metadata; + arr + } } -impl NativeArray for WKBArray { +impl ArrayBase for WKBArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -156,24 +157,10 @@ impl NativeArray for WKBArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - CoordType::Interleaved - } - - fn to_coord_type(&self, _coord_type: CoordType) -> Arc { - Arc::new(self.clone()) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -184,31 +171,9 @@ impl NativeArray for WKBArray { fn nulls(&self) -> Option<&NullBuffer> { self.array.nulls() } - - fn as_ref(&self) -> &dyn NativeArray { - self - } - - fn slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.slice(offset, length)) - } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } -} - -impl GeometryArraySelfMethods<2> for WKBArray { - fn with_coords(self, _coords: crate::array::CoordBuffer<2>) -> Self { - unimplemented!() - } - - fn into_coord_type(self, _coord_type: CoordType) -> Self { - self - } } -impl<'a, O: OffsetSizeTrait> NativeArrayAccessor<'a> for WKBArray { +impl<'a, O: OffsetSizeTrait> ArrayAccessor<'a> for WKBArray { type Item = WKB<'a, O>; type ItemGeo = geo::Geometry; diff --git a/src/array/cast.rs b/src/array/cast.rs index dc86fa11b..fe56ad897 100644 --- a/src/array/cast.rs +++ b/src/array/cast.rs @@ -437,24 +437,6 @@ pub trait AsChunkedNativeArray { self.as_large_geometry_collection_opt::().unwrap() } - /// Downcast this to a [`ChunkedWKBArray`] with `i32` offsets returning `None` if not possible - fn as_wkb_opt(&self) -> Option<&ChunkedWKBArray>; - - /// Downcast this to a [`ChunkedWKBArray`] with `i32` offsets panicking if not possible - #[inline] - fn as_wkb(&self) -> &ChunkedWKBArray { - self.as_wkb_opt().unwrap() - } - - /// Downcast this to a [`ChunkedWKBArray`] with `i64` offsets returning `None` if not possible - fn as_large_wkb_opt(&self) -> Option<&ChunkedWKBArray>; - - /// Downcast this to a [`ChunkedWKBArray`] with `i64` offsets panicking if not possible - #[inline] - fn as_large_wkb(&self) -> &ChunkedWKBArray { - self.as_large_wkb_opt().unwrap() - } - /// Downcast this to a [`ChunkedRectArray`] returning `None` if not possible fn as_rect_opt(&self) -> Option<&ChunkedRectArray>; @@ -564,17 +546,39 @@ impl AsChunkedNativeArray for &dyn ChunkedNativeArray { } #[inline] - fn as_wkb_opt(&self) -> Option<&ChunkedWKBArray> { - self.as_any().downcast_ref::>() + fn as_rect_opt(&self) -> Option<&ChunkedRectArray> { + self.as_any().downcast_ref::>() } +} +pub trait AsChunkedSerializedArray { + /// Downcast this to a [`ChunkedWKBArray`] with `i32` offsets returning `None` if not possible + fn as_wkb_opt(&self) -> Option<&ChunkedWKBArray>; + + /// Downcast this to a [`ChunkedWKBArray`] with `i32` offsets panicking if not possible #[inline] - fn as_large_wkb_opt(&self) -> Option<&ChunkedWKBArray> { - self.as_any().downcast_ref::>() + fn as_wkb(&self) -> &ChunkedWKBArray { + self.as_wkb_opt().unwrap() } + /// Downcast this to a [`ChunkedWKBArray`] with `i64` offsets returning `None` if not possible + fn as_large_wkb_opt(&self) -> Option<&ChunkedWKBArray>; + + /// Downcast this to a [`ChunkedWKBArray`] with `i64` offsets panicking if not possible #[inline] - fn as_rect_opt(&self) -> Option<&ChunkedRectArray> { - self.as_any().downcast_ref::>() + fn as_large_wkb(&self) -> &ChunkedWKBArray { + self.as_large_wkb_opt().unwrap() } } + +// impl AsChunkedSerializedArray for &dyn ChunkedNativeArray { +// #[inline] +// fn as_wkb_opt(&self) -> Option<&ChunkedWKBArray> { +// self.as_any().downcast_ref::>() +// } + +// #[inline] +// fn as_large_wkb_opt(&self) -> Option<&ChunkedWKBArray> { +// self.as_any().downcast_ref::>() +// } +// } diff --git a/src/array/dynamic.rs b/src/array/dynamic.rs index 5934face2..1217d4ecb 100644 --- a/src/array/dynamic.rs +++ b/src/array/dynamic.rs @@ -7,9 +7,9 @@ use arrow_schema::{DataType, FieldRef}; use crate::array::metadata::ArrayMetadata; use crate::array::CoordType; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::trait_::NativeArrayRef; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; #[derive(Debug, Clone)] #[repr(transparent)] @@ -41,15 +41,11 @@ impl From for NativeArrayRef { } } -impl NativeArray for NativeArrayDyn { +impl ArrayBase for NativeArrayDyn { fn as_any(&self) -> &dyn std::any::Any { self.0.as_any() } - fn data_type(&self) -> GeoDataType { - self.0.data_type() - } - fn storage_type(&self) -> DataType { self.0.storage_type() } @@ -71,14 +67,6 @@ impl NativeArray for NativeArrayDyn { self.0.to_array_ref() } - fn coord_type(&self) -> CoordType { - self.0.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - self.0.to_coord_type(coord_type) - } - fn len(&self) -> usize { self.0.len() } @@ -90,6 +78,20 @@ impl NativeArray for NativeArrayDyn { fn metadata(&self) -> Arc { self.0.metadata() } +} + +impl NativeArray for NativeArrayDyn { + fn data_type(&self) -> NativeType { + self.0.data_type() + } + + fn coord_type(&self) -> CoordType { + self.0.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + self.0.to_coord_type(coord_type) + } fn with_metadata(&self, metadata: Arc) -> NativeArrayRef { self.0.with_metadata(metadata) diff --git a/src/array/geometry/array.rs b/src/array/geometry/array.rs index a3235899d..70d81dd60 100644 --- a/src/array/geometry/array.rs +++ b/src/array/geometry/array.rs @@ -12,10 +12,10 @@ use crate::array::{ CoordType, LineStringArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, PointArray, PolygonArray, RectArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::GeoArrowError; use crate::scalar::Geometry; -use crate::trait_::{NativeArrayAccessor, GeometryArraySelfMethods, IntoArrow}; +use crate::trait_::{GeometryArraySelfMethods, IntoArrow, ArrayAccessor}; use crate::NativeArray; /// A GeometryArray is an enum over the various underlying _zero copy_ GeoArrow array types. @@ -49,7 +49,7 @@ impl NativeArray for GeometryArray { } } - fn data_type(&self) -> &GeoDataType { + fn data_type(&self) -> &NativeType { match self { GeometryArray::Point(arr) => arr.data_type(), GeometryArray::LineString(arr) => arr.data_type(), @@ -252,7 +252,7 @@ impl GeometryArraySelfMethods for GeometryArray { } } -impl<'a, O: OffsetSizeTrait> NativeArrayAccessor<'a> for GeometryArray { +impl<'a, O: OffsetSizeTrait> ArrayAccessor<'a> for GeometryArray { type Item = Geometry<'a, O>; type ItemGeo = geo::Geometry; diff --git a/src/array/geometrycollection/array.rs b/src/array/geometrycollection/array.rs index 6eef732fb..fc3a44522 100644 --- a/src/array/geometrycollection/array.rs +++ b/src/array/geometrycollection/array.rs @@ -15,12 +15,12 @@ use crate::array::{ CoordBuffer, CoordType, LineStringArray, MixedGeometryArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, PointArray, PolygonArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::GeometryCollectionTrait; use crate::scalar::GeometryCollection; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; -use crate::NativeArray; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; +use crate::{ArrayBase, NativeArray}; /// An immutable array of GeometryCollection geometries using GeoArrow's in-memory representation. /// @@ -28,8 +28,8 @@ use crate::NativeArray; /// validity bitmap. #[derive(Debug, Clone)] pub struct GeometryCollectionArray { - // Always GeoDataType::GeometryCollection or GeoDataType::LargeGeometryCollection - data_type: GeoDataType, + // Always NativeType::GeometryCollection or NativeType::LargeGeometryCollection + data_type: NativeType, metadata: Arc, @@ -56,8 +56,8 @@ impl GeometryCollectionArray { ) -> Self { let coord_type = array.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeGeometryCollection(coord_type, D.try_into().unwrap()), - false => GeoDataType::GeometryCollection(coord_type, D.try_into().unwrap()), + true => NativeType::LargeGeometryCollection(coord_type, D.try_into().unwrap()), + false => NativeType::GeometryCollection(coord_type, D.try_into().unwrap()), }; Self { @@ -165,15 +165,11 @@ impl GeometryCollectionArray { } } -impl NativeArray for GeometryCollectionArray { +impl ArrayBase for GeometryCollectionArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -196,24 +192,10 @@ impl NativeArray for GeometryCollectionArray self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.array.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -226,6 +208,26 @@ impl NativeArray for GeometryCollectionArray fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for GeometryCollectionArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.array.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -252,9 +254,7 @@ impl GeometryArraySelfMethods } } -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> - for GeometryCollectionArray -{ +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for GeometryCollectionArray { type Item = GeometryCollection<'a, O, D>; type ItemGeo = geo::GeometryCollection; diff --git a/src/array/geometrycollection/builder.rs b/src/array/geometrycollection/builder.rs index 3c0a50a5d..51040709b 100644 --- a/src/array/geometrycollection/builder.rs +++ b/src/array/geometrycollection/builder.rs @@ -14,7 +14,7 @@ use crate::geo_traits::{ }; use crate::io::wkb::reader::WKBGeometry; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; /// The GeoArrow equivalent to `Vec>`: a mutable collection of /// GeometryCollections. diff --git a/src/array/linestring/array.rs b/src/array/linestring/array.rs index dcfe3a04a..1a4183789 100644 --- a/src/array/linestring/array.rs +++ b/src/array/linestring/array.rs @@ -13,13 +13,13 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, MultiLineStringArray, MultiPointArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::LineStringTrait; use crate::scalar::LineString; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, ArrayRef, GenericListArray, LargeListArray, ListArray, OffsetSizeTrait}; use arrow_buffer::{NullBuffer, OffsetBuffer}; use arrow_schema::{DataType, Field, FieldRef}; @@ -32,8 +32,8 @@ use super::LineStringBuilder; /// bitmap. #[derive(Debug, Clone)] pub struct LineStringArray { - // Always GeoDataType::LineString or GeoDataType::LargeLineString - data_type: GeoDataType, + // Always NativeType::LineString or NativeType::LargeLineString + data_type: NativeType, pub(crate) metadata: Arc, @@ -106,8 +106,8 @@ impl LineStringArray { let coord_type = coords.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeLineString(coord_type, D.try_into()?), - false => GeoDataType::LineString(coord_type, D.try_into()?), + true => NativeType::LargeLineString(coord_type, D.try_into()?), + false => NativeType::LineString(coord_type, D.try_into()?), }; Ok(Self { @@ -234,15 +234,11 @@ impl LineStringArray { } } -impl NativeArray for LineStringArray { +impl ArrayBase for LineStringArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -274,24 +270,10 @@ impl NativeArray for LineStringArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -303,6 +285,26 @@ impl NativeArray for LineStringArray { fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for LineStringArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -333,7 +335,7 @@ impl GeometryArraySelfMethods for LineStr } } -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> for LineStringArray { +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for LineStringArray { type Item = LineString<'a, O, D>; type ItemGeo = geo::LineString; diff --git a/src/array/linestring/builder.rs b/src/array/linestring/builder.rs index d0e94419a..d0b9e5ec0 100644 --- a/src/array/linestring/builder.rs +++ b/src/array/linestring/builder.rs @@ -12,7 +12,7 @@ use crate::geo_traits::{ }; use crate::io::wkb::reader::WKBLineString; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; use arrow_buffer::NullBufferBuilder; use std::convert::From; diff --git a/src/array/mixed/array.rs b/src/array/mixed/array.rs index b174198ab..3477ad766 100644 --- a/src/array/mixed/array.rs +++ b/src/array/mixed/array.rs @@ -13,12 +13,12 @@ use crate::array::{ CoordType, GeometryCollectionArray, LineStringArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, PointArray, PolygonArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::GeometryTrait; use crate::scalar::Geometry; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; -use crate::NativeArray; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; +use crate::{ArrayBase, NativeArray}; /// # Invariants /// @@ -55,12 +55,12 @@ use crate::NativeArray; /// - 37: GeometryCollection ZM #[derive(Debug, Clone, PartialEq)] pub struct MixedGeometryArray { - /// Always GeoDataType::Mixed or GeoDataType::LargeMixed - data_type: GeoDataType, + /// Always NativeType::Mixed or NativeType::LargeMixed + data_type: NativeType, pub(crate) metadata: Arc, - /// Invariant: every item in `type_ids` is `> 0 && < fields.len()` if `type_ids` are not provided. If `type_ids` exist in the GeoDataType, then every item in `type_ids` is `> 0 && ` + /// Invariant: every item in `type_ids` is `> 0 && < fields.len()` if `type_ids` are not provided. If `type_ids` exist in the NativeType, then every item in `type_ids` is `> 0 && ` pub(crate) type_ids: ScalarBuffer, /// Invariant: `offsets.len() == type_ids.len()` @@ -168,8 +168,8 @@ impl MixedGeometryArray { let coord_type = coord_types.into_iter().next().unwrap(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeMixed(coord_type, D.try_into().unwrap()), - false => GeoDataType::Mixed(coord_type, D.try_into().unwrap()), + true => NativeType::LargeMixed(coord_type, D.try_into().unwrap()), + false => NativeType::Mixed(coord_type, D.try_into().unwrap()), }; Self { @@ -363,15 +363,11 @@ impl MixedGeometryArray { } } -impl NativeArray for MixedGeometryArray { +impl ArrayBase for MixedGeometryArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -395,24 +391,10 @@ impl NativeArray for MixedGeometryArray crate::array::CoordType { - self.data_type.coord_type().unwrap() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -425,6 +407,26 @@ impl NativeArray for MixedGeometryArray Option<&NullBuffer> { None } +} + +impl NativeArray for MixedGeometryArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> crate::array::CoordType { + self.data_type.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -449,7 +451,7 @@ impl GeometryArraySelfMethods for MixedGe } } -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> for MixedGeometryArray { +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for MixedGeometryArray { type Item = Geometry<'a, O, D>; type ItemGeo = geo::Geometry; diff --git a/src/array/mixed/builder.rs b/src/array/mixed/builder.rs index 970cb1a1f..3abb5373e 100644 --- a/src/array/mixed/builder.rs +++ b/src/array/mixed/builder.rs @@ -11,8 +11,8 @@ use crate::error::{GeoArrowError, Result}; use crate::geo_traits::*; use crate::io::wkb::reader::WKBGeometry; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; -use crate::NativeArray; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; +use crate::{ArrayBase, NativeArray}; use arrow_array::{OffsetSizeTrait, UnionArray}; /// The GeoArrow equivalent to a `Vec>`: a mutable collection of Geometries. diff --git a/src/array/mod.rs b/src/array/mod.rs index 6cca65b5f..7629cfede 100644 --- a/src/array/mod.rs +++ b/src/array/mod.rs @@ -21,6 +21,8 @@ pub use point::{PointArray, PointBuilder}; pub use polygon::{PolygonArray, PolygonBuilder, PolygonCapacity}; pub use rect::{RectArray, RectBuilder}; +pub use crate::trait_::{ArrayBase, NativeArray}; + pub(crate) mod binary; mod cast; pub(crate) mod coord; @@ -44,16 +46,15 @@ use std::sync::Arc; use arrow_array::Array; use arrow_schema::Field; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::Result; -use crate::NativeArray; /// Convert an Arrow [Array] to a geoarrow GeometryArray pub fn from_arrow_array(array: &dyn Array, field: &Field) -> Result> { - let data_type = GeoDataType::try_from(field)?; + let data_type = NativeType::try_from(field)?; use Dimension::*; - use GeoDataType::*; + use NativeType::*; let geo_arr: Arc = match data_type { Point(_, dim) => match dim { XY => Arc::new(PointArray::<2>::try_from((array, field))?), @@ -115,8 +116,8 @@ pub fn from_arrow_array(array: &dyn Array, field: &Field) -> Result Arc::new(GeometryCollectionArray::::try_from((array, field))?), XYZ => Arc::new(GeometryCollectionArray::::try_from((array, field))?), }, - WKB => Arc::new(WKBArray::::try_from((array, field))?), - LargeWKB => Arc::new(WKBArray::::try_from((array, field))?), + // WKB => Arc::new(WKBArray::::try_from((array, field))?), + // LargeWKB => Arc::new(WKBArray::::try_from((array, field))?), Rect(dim) => match dim { XY => Arc::new(RectArray::<2>::try_from((array, field))?), XYZ => Arc::new(RectArray::<3>::try_from((array, field))?), diff --git a/src/array/multilinestring/array.rs b/src/array/multilinestring/array.rs index 5c8075fec..84687ca13 100644 --- a/src/array/multilinestring/array.rs +++ b/src/array/multilinestring/array.rs @@ -11,13 +11,13 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, LineStringArray, MixedGeometryArray, PolygonArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::MultiLineStringTrait; use crate::scalar::MultiLineString; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, GenericListArray, LargeListArray, ListArray, OffsetSizeTrait}; use arrow_buffer::{NullBuffer, OffsetBuffer}; use arrow_schema::{DataType, Field}; @@ -30,8 +30,8 @@ use super::MultiLineStringBuilder; /// bitmap. #[derive(Debug, Clone)] pub struct MultiLineStringArray { - // Always GeoDataType::MultiLineString or GeoDataType::LargeMultiLineString - data_type: GeoDataType, + // Always NativeType::MultiLineString or NativeType::LargeMultiLineString + data_type: NativeType, pub(crate) metadata: Arc, @@ -123,8 +123,8 @@ impl MultiLineStringArray { let coord_type = coords.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeMultiLineString(coord_type, D.try_into()?), - false => GeoDataType::MultiLineString(coord_type, D.try_into()?), + true => NativeType::LargeMultiLineString(coord_type, D.try_into()?), + false => NativeType::MultiLineString(coord_type, D.try_into()?), }; Ok(Self { @@ -268,15 +268,11 @@ impl MultiLineStringArray { } } -impl NativeArray for MultiLineStringArray { +impl ArrayBase for MultiLineStringArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -299,24 +295,10 @@ impl NativeArray for MultiLineStringArray CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -328,6 +310,26 @@ impl NativeArray for MultiLineStringArray Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for MultiLineStringArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -368,9 +370,7 @@ impl GeometryArraySelfMethods } // Implement geometry accessors -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> - for MultiLineStringArray -{ +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for MultiLineStringArray { type Item = MultiLineString<'a, O, D>; type ItemGeo = geo::MultiLineString; diff --git a/src/array/multilinestring/builder.rs b/src/array/multilinestring/builder.rs index 3f72db2ac..7c8b431a7 100644 --- a/src/array/multilinestring/builder.rs +++ b/src/array/multilinestring/builder.rs @@ -14,7 +14,7 @@ use crate::geo_traits::{ }; use crate::io::wkb::reader::WKBMaybeMultiLineString; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; use arrow_buffer::{NullBufferBuilder, OffsetBuffer}; diff --git a/src/array/multipoint/array.rs b/src/array/multipoint/array.rs index 04160a5ad..bfb0871c1 100644 --- a/src/array/multipoint/array.rs +++ b/src/array/multipoint/array.rs @@ -12,13 +12,13 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, LineStringArray, MixedGeometryArray, PointArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::MultiPointTrait; use crate::scalar::MultiPoint; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, GenericListArray, LargeListArray, ListArray, OffsetSizeTrait}; use arrow_buffer::{NullBuffer, OffsetBuffer}; use arrow_schema::{DataType, Field}; @@ -29,8 +29,8 @@ use arrow_schema::{DataType, Field}; /// bitmap. #[derive(Debug, Clone)] pub struct MultiPointArray { - // Always GeoDataType::MultiPoint or GeoDataType::LargeMultiPoint - data_type: GeoDataType, + // Always NativeType::MultiPoint or NativeType::LargeMultiPoint + data_type: NativeType, pub(crate) metadata: Arc, @@ -103,8 +103,8 @@ impl MultiPointArray { let coord_type = coords.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeMultiPoint(coord_type, D.try_into()?), - false => GeoDataType::MultiPoint(coord_type, D.try_into()?), + true => NativeType::LargeMultiPoint(coord_type, D.try_into()?), + false => NativeType::MultiPoint(coord_type, D.try_into()?), }; Ok(Self { @@ -230,15 +230,11 @@ impl MultiPointArray { } } -impl NativeArray for MultiPointArray { +impl ArrayBase for MultiPointArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -261,24 +257,10 @@ impl NativeArray for MultiPointArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -290,6 +272,26 @@ impl NativeArray for MultiPointArray { fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for MultiPointArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -321,7 +323,7 @@ impl GeometryArraySelfMethods for MultiPo } // Implement geometry accessors -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> for MultiPointArray { +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for MultiPointArray { type Item = MultiPoint<'a, O, D>; type ItemGeo = geo::MultiPoint; diff --git a/src/array/multipoint/builder.rs b/src/array/multipoint/builder.rs index 6de7afde9..313a2522c 100644 --- a/src/array/multipoint/builder.rs +++ b/src/array/multipoint/builder.rs @@ -12,7 +12,7 @@ use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{CoordTrait, GeometryTrait, GeometryType, MultiPointTrait, PointTrait}; use crate::io::wkb::reader::WKBMaybeMultiPoint; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; use arrow_buffer::NullBufferBuilder; diff --git a/src/array/multipolygon/array.rs b/src/array/multipolygon/array.rs index 637e8d541..0abee351d 100644 --- a/src/array/multipolygon/array.rs +++ b/src/array/multipolygon/array.rs @@ -10,13 +10,13 @@ use crate::array::util::{ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, PolygonArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::MultiPolygonTrait; use crate::scalar::MultiPolygon; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, GenericListArray, LargeListArray, ListArray, OffsetSizeTrait}; use arrow_buffer::{NullBuffer, OffsetBuffer}; @@ -30,8 +30,8 @@ use super::MultiPolygonBuilder; /// bitmap. #[derive(Debug, Clone)] pub struct MultiPolygonArray { - // Always GeoDataType::MultiPolygon or GeoDataType::LargeMultiPolygon - data_type: GeoDataType, + // Always NativeType::MultiPolygon or NativeType::LargeMultiPolygon + data_type: NativeType, pub(crate) metadata: Arc, @@ -145,8 +145,8 @@ impl MultiPolygonArray { let coord_type = coords.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargeMultiPolygon(coord_type, D.try_into()?), - false => GeoDataType::MultiPolygon(coord_type, D.try_into()?), + true => NativeType::LargeMultiPolygon(coord_type, D.try_into()?), + false => NativeType::MultiPolygon(coord_type, D.try_into()?), }; Ok(Self { @@ -335,15 +335,11 @@ impl MultiPolygonArray { } } -impl NativeArray for MultiPolygonArray { +impl ArrayBase for MultiPolygonArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -366,24 +362,10 @@ impl NativeArray for MultiPolygonArray self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -395,6 +377,26 @@ impl NativeArray for MultiPolygonArray fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for MultiPolygonArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -435,7 +437,7 @@ impl GeometryArraySelfMethods for MultiPo } // Implement geometry accessors -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> for MultiPolygonArray { +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for MultiPolygonArray { type Item = MultiPolygon<'a, O, D>; type ItemGeo = geo::MultiPolygon; diff --git a/src/array/multipolygon/builder.rs b/src/array/multipolygon/builder.rs index 34b7fce91..f94402274 100644 --- a/src/array/multipolygon/builder.rs +++ b/src/array/multipolygon/builder.rs @@ -14,7 +14,7 @@ use crate::geo_traits::{ }; use crate::io::wkb::reader::WKBMaybeMultiPolygon; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; use arrow_buffer::{NullBufferBuilder, OffsetBuffer}; diff --git a/src/array/point/array.rs b/src/array/point/array.rs index 1b7b1e20e..af4c9f801 100644 --- a/src/array/point/array.rs +++ b/src/array/point/array.rs @@ -7,13 +7,13 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, InterleavedCoordBuffer, MixedGeometryArray, MultiPointArray, PointBuilder, SeparatedCoordBuffer, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::GeoArrowError; use crate::geo_traits::PointTrait; use crate::scalar::Point; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::owned_slice_validity; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, ArrayRef, FixedSizeListArray, OffsetSizeTrait, StructArray}; use arrow_buffer::NullBuffer; @@ -24,8 +24,8 @@ use arrow_schema::{DataType, Field}; /// This is semantically equivalent to `Vec>` due to the internal validity bitmap. #[derive(Debug, Clone)] pub struct PointArray { - // Always GeoDataType::Point - data_type: GeoDataType, + // Always NativeType::Point + data_type: NativeType, pub(crate) metadata: Arc, pub(crate) coords: CoordBuffer, pub(crate) validity: Option, @@ -77,7 +77,7 @@ impl PointArray { metadata: Arc, ) -> Result { check(&coords, validity.as_ref().map(|v| v.len()))?; - let data_type = GeoDataType::Point(coords.coord_type(), D.try_into()?); + let data_type = NativeType::Point(coords.coord_type(), D.try_into()?); Ok(Self { data_type, coords, @@ -149,15 +149,11 @@ impl PointArray { } } -impl NativeArray for PointArray { +impl ArrayBase for PointArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -180,24 +176,10 @@ impl NativeArray for PointArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.to_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -209,6 +191,26 @@ impl NativeArray for PointArray { fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for PointArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.to_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -235,7 +237,7 @@ impl GeometryArraySelfMethods for PointArray { } // Implement geometry accessors -impl<'a, const D: usize> NativeArrayAccessor<'a> for PointArray { +impl<'a, const D: usize> ArrayAccessor<'a> for PointArray { type Item = Point<'a, D>; type ItemGeo = geo::Point; diff --git a/src/array/point/builder.rs b/src/array/point/builder.rs index fc18ba841..2de38a001 100644 --- a/src/array/point/builder.rs +++ b/src/array/point/builder.rs @@ -11,7 +11,7 @@ use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{GeometryTrait, GeometryType, MultiPointTrait, PointTrait}; use crate::io::wkb::reader::WKBPoint; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, OffsetSizeTrait}; use arrow_buffer::NullBufferBuilder; diff --git a/src/array/polygon/array.rs b/src/array/polygon/array.rs index 2035695f0..eb7e3d5ee 100644 --- a/src/array/polygon/array.rs +++ b/src/array/polygon/array.rs @@ -12,13 +12,13 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, MultiLineStringArray, MultiPolygonArray, RectArray, WKBArray, }; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::PolygonTrait; use crate::scalar::Polygon; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::{owned_slice_offsets, owned_slice_validity}; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, OffsetSizeTrait}; use arrow_array::{GenericListArray, LargeListArray, ListArray}; @@ -33,8 +33,8 @@ use super::PolygonBuilder; #[derive(Debug, Clone)] // #[derive(Debug, Clone, PartialEq)] pub struct PolygonArray { - // Always GeoDataType::Polygon or GeoDataType::LargePolygon - data_type: GeoDataType, + // Always NativeType::Polygon or NativeType::LargePolygon + data_type: NativeType, pub(crate) metadata: Arc, @@ -126,8 +126,8 @@ impl PolygonArray { let coord_type = coords.coord_type(); let data_type = match O::IS_LARGE { - true => GeoDataType::LargePolygon(coord_type, D.try_into()?), - false => GeoDataType::Polygon(coord_type, D.try_into()?), + true => NativeType::LargePolygon(coord_type, D.try_into()?), + false => NativeType::Polygon(coord_type, D.try_into()?), }; Ok(Self { @@ -272,15 +272,11 @@ impl PolygonArray { } } -impl NativeArray for PolygonArray { +impl ArrayBase for PolygonArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -303,24 +299,10 @@ impl NativeArray for PolygonArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - self.coords.coord_type() - } - - fn to_coord_type(&self, coord_type: CoordType) -> Arc { - Arc::new(self.clone().into_coord_type(coord_type)) - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -332,6 +314,26 @@ impl NativeArray for PolygonArray { fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for PolygonArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + self.coords.coord_type() + } + + fn to_coord_type(&self, coord_type: CoordType) -> Arc { + Arc::new(self.clone().into_coord_type(coord_type)) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -370,7 +372,7 @@ impl GeometryArraySelfMethods for Polygon } // Implement geometry accessors -impl<'a, O: OffsetSizeTrait, const D: usize> NativeArrayAccessor<'a> for PolygonArray { +impl<'a, O: OffsetSizeTrait, const D: usize> ArrayAccessor<'a> for PolygonArray { type Item = Polygon<'a, O, D>; type ItemGeo = geo::Polygon; diff --git a/src/array/polygon/builder.rs b/src/array/polygon/builder.rs index fce68fe50..37858a3d7 100644 --- a/src/array/polygon/builder.rs +++ b/src/array/polygon/builder.rs @@ -15,7 +15,7 @@ use crate::geo_traits::{ }; use crate::io::wkb::reader::WKBPolygon; use crate::scalar::WKB; -use crate::trait_::{GeometryArrayBuilder, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; use arrow_buffer::{NullBufferBuilder, OffsetBuffer}; diff --git a/src/array/rect/array.rs b/src/array/rect/array.rs index 11b3d3666..b7af5a067 100644 --- a/src/array/rect/array.rs +++ b/src/array/rect/array.rs @@ -9,13 +9,13 @@ use arrow_schema::{DataType, Field}; use crate::array::metadata::ArrayMetadata; use crate::array::rect::RectBuilder; use crate::array::{CoordBuffer, CoordType, SeparatedCoordBuffer}; -use crate::datatypes::{rect_fields, GeoDataType}; +use crate::datatypes::{rect_fields, NativeType}; use crate::error::GeoArrowError; use crate::geo_traits::RectTrait; use crate::scalar::Rect; -use crate::trait_::{GeometryArraySelfMethods, IntoArrow, NativeArrayAccessor}; +use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; use crate::util::owned_slice_validity; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; /// An immutable array of Rect geometries. /// @@ -26,8 +26,8 @@ use crate::NativeArray; /// Internally this is implemented as a FixedSizeList, laid out as minx, miny, maxx, maxy. #[derive(Debug, Clone, PartialEq)] pub struct RectArray { - // Always GeoDataType::Rect - data_type: GeoDataType, + // Always NativeType::Rect + data_type: NativeType, metadata: Arc, @@ -47,7 +47,7 @@ impl RectArray { validity: Option, metadata: Arc, ) -> Self { - let data_type = GeoDataType::Rect(D.try_into().unwrap()); + let data_type = NativeType::Rect(D.try_into().unwrap()); Self { data_type, lower, @@ -92,15 +92,11 @@ impl RectArray { } } -impl NativeArray for RectArray { +impl ArrayBase for RectArray { fn as_any(&self) -> &dyn std::any::Any { self } - fn data_type(&self) -> GeoDataType { - self.data_type - } - fn storage_type(&self) -> DataType { self.data_type.to_data_type() } @@ -123,24 +119,10 @@ impl NativeArray for RectArray { self.clone().into_array_ref() } - fn coord_type(&self) -> CoordType { - unimplemented!() - } - - fn to_coord_type(&self, _coord_type: CoordType) -> Arc { - todo!() - } - fn metadata(&self) -> Arc { self.metadata.clone() } - fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { - let mut arr = self.clone(); - arr.metadata = metadata; - Arc::new(arr) - } - /// Returns the number of geometries in this array #[inline] fn len(&self) -> usize { @@ -152,6 +134,26 @@ impl NativeArray for RectArray { fn nulls(&self) -> Option<&NullBuffer> { self.validity.as_ref() } +} + +impl NativeArray for RectArray { + fn data_type(&self) -> NativeType { + self.data_type + } + + fn coord_type(&self) -> CoordType { + CoordType::Separated + } + + fn to_coord_type(&self, _coord_type: CoordType) -> Arc { + Arc::new(self.clone()) + } + + fn with_metadata(&self, metadata: Arc) -> crate::trait_::NativeArrayRef { + let mut arr = self.clone(); + arr.metadata = metadata; + Arc::new(arr) + } fn as_ref(&self) -> &dyn NativeArray { self @@ -176,7 +178,7 @@ impl GeometryArraySelfMethods for RectArray { } } -impl<'a, const D: usize> NativeArrayAccessor<'a> for RectArray { +impl<'a, const D: usize> ArrayAccessor<'a> for RectArray { type Item = Rect<'a, D>; type ItemGeo = geo::Rect; diff --git a/src/chunked_array.rs b/src/chunked_array.rs index c3f75a19b..5ba41f29b 100644 --- a/src/chunked_array.rs +++ b/src/chunked_array.rs @@ -19,9 +19,9 @@ use arrow_schema::{DataType, Field}; use rayon::prelude::*; use crate::array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::trait_::{NativeArrayAccessor, NativeArrayRef}; +use crate::trait_::{ArrayAccessor, NativeArrayRef}; use crate::NativeArray; /// A collection of Arrow arrays of the same type. @@ -378,14 +378,14 @@ impl ChunkedGeometryArray { /// # Examples /// /// ``` - /// use geoarrow::{chunked_array::ChunkedGeometryArray, array::PointArray, datatypes::GeoDataType}; + /// use geoarrow::{chunked_array::ChunkedGeometryArray, array::PointArray, datatypes::NativeType}; /// /// let array_0: PointArray<2> = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); /// let array_1: PointArray<2> = vec![&geo::point!(x: 3., y: 4.)].as_slice().into(); /// let chunked_array = ChunkedGeometryArray::new(vec![array_0, array_1]); - /// assert!(matches!(chunked_array.data_type(), GeoDataType::Point(_, _))); + /// assert!(matches!(chunked_array.data_type(), NativeType::Point(_, _))); /// ``` - pub fn data_type(&self) -> GeoDataType { + pub fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -398,7 +398,7 @@ impl ChunkedGeometryArray { /// chunked_array::ChunkedGeometryArray, /// array::PointArray, /// trait_::NativeArray, - /// datatypes::GeoDataType, + /// datatypes::NativeType, /// }; /// /// let array_0: PointArray<2> = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); @@ -433,7 +433,7 @@ impl ChunkedGeometryArray { /// chunked_array::ChunkedGeometryArray, /// array::PointArray, /// trait_::NativeArray, - /// datatypes::GeoDataType, + /// datatypes::NativeType, /// }; /// /// let array_0: PointArray<2> = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); @@ -468,7 +468,7 @@ impl ChunkedGeometryArray { /// chunked_array::ChunkedGeometryArray, /// array::PointArray, /// trait_::NativeArray, - /// datatypes::GeoDataType, + /// datatypes::NativeType, /// }; /// /// let array_0: PointArray<2> = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); @@ -493,7 +493,7 @@ impl ChunkedGeometryArray { } } -impl<'a, G: NativeArray + NativeArrayAccessor<'a>> ChunkedGeometryArray { +impl<'a, G: NativeArray + ArrayAccessor<'a>> ChunkedGeometryArray { /// Returns a value from this chunked array, ignoring validity. /// /// # Examples @@ -613,7 +613,7 @@ pub trait ChunkedNativeArray: std::fmt::Debug + Send + Sync { /// ``` fn as_any(&self) -> &dyn Any; - /// Returns a reference to the [`GeoDataType`] of this array. + /// Returns a reference to the [`NativeType`] of this array. /// /// # Examples /// @@ -628,7 +628,7 @@ pub trait ChunkedNativeArray: std::fmt::Debug + Send + Sync { /// let chunked_array = ChunkedGeometryArray::new(vec![array_0, array_1]); /// let data_type = chunked_array.data_type(); /// ``` - fn data_type(&self) -> GeoDataType; + fn data_type(&self) -> NativeType; /// Returns an Arrow [`Field`] describing this chunked array. /// @@ -794,7 +794,7 @@ impl ChunkedNativeArray for ChunkedPointArray { self } - fn data_type(&self) -> GeoDataType { + fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -836,7 +836,7 @@ impl ChunkedNativeArray for ChunkedWKBArray { self } - fn data_type(&self) -> GeoDataType { + fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -880,7 +880,7 @@ macro_rules! impl_trait { self } - fn data_type(&self) -> GeoDataType { + fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -932,7 +932,7 @@ impl ChunkedNativeArray for ChunkedRectArray { self } - fn data_type(&self) -> GeoDataType { + fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -1005,9 +1005,9 @@ pub fn from_arrow_chunks( ))) }; } - use GeoDataType::*; + use NativeType::*; - let geo_data_type = GeoDataType::try_from(field)?; + let geo_data_type = NativeType::try_from(field)?; match geo_data_type { Point(_, Dimension::XY) => impl_downcast!(PointArray<2>), LineString(_, Dimension::XY) => impl_downcast!(LineStringArray), @@ -1096,7 +1096,7 @@ pub fn from_geoarrow_chunks(chunks: &[&dyn NativeArray]) -> Result = match data_types.drain().next().unwrap() { Point(_, Dimension::XY) => impl_downcast!(as_point, 2), LineString(_, Dimension::XY) => impl_downcast!(as_line_string, 2), diff --git a/src/datatypes.rs b/src/datatypes.rs index 8d7b0051d..f5ee4394a 100644 --- a/src/datatypes.rs +++ b/src/datatypes.rs @@ -1,4 +1,4 @@ -//! Contains the implementation of [`GeoDataType`], which defines all geometry arrays in this +//! Contains the implementation of [`NativeType`], which defines all geometry arrays in this //! crate. use std::collections::{HashMap, HashSet}; @@ -76,7 +76,7 @@ impl TryFrom for Dimension { /// It must always be possible to accurately downcast from a `dyn &NativeArray` or `dyn /// &ChunkedNativeArray` to a unique concrete array type using this enum. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum GeoDataType { +pub enum NativeType { /// Represents a [PointArray][crate::array::PointArray] or /// [ChunkedPointArray][crate::chunked_array::ChunkedPointArray]. Point(CoordType, Dimension), @@ -145,6 +145,13 @@ pub enum GeoDataType { /// `i64` offsets. LargeGeometryCollection(CoordType, Dimension), + /// Represents a [RectArray][crate::array::RectArray] or + /// [ChunkedRectArray][crate::chunked_array::ChunkedRectArray]. + Rect(Dimension), +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum SerializedType { /// Represents a [WKBArray][crate::array::WKBArray] or /// [ChunkedWKBArray][crate::chunked_array::ChunkedWKBArray] with `i32` offsets. WKB, @@ -152,10 +159,12 @@ pub enum GeoDataType { /// Represents a [WKBArray][crate::array::WKBArray] or /// [ChunkedWKBArray][crate::chunked_array::ChunkedWKBArray] with `i64` offsets. LargeWKB, +} - /// Represents a [RectArray][crate::array::RectArray] or - /// [ChunkedRectArray][crate::chunked_array::ChunkedRectArray]. - Rect(Dimension), +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum AnyType { + Native(NativeType), + Serialized(SerializedType), } pub(crate) fn coord_type_to_data_type(coord_type: CoordType, dim: Dimension) -> DataType { @@ -186,7 +195,6 @@ pub(crate) fn coord_type_to_data_type(coord_type: CoordType, dim: Dimension) -> } } -// TODO: these are duplicated from the arrays fn point_data_type(coord_type: CoordType, dim: Dimension) -> DataType { coord_type_to_data_type(coord_type, dim) } @@ -268,37 +276,37 @@ fn mixed_data_type(coord_type: CoordType, dim: Dimension) -> // GeoArrow extension metadata fields.push(Field::new( "", - GeoDataType::Point(coord_type, dim).to_data_type(), + NativeType::Point(coord_type, dim).to_data_type(), true, )); let linestring = match O::IS_LARGE { - true => GeoDataType::LargeLineString(coord_type, dim), - false => GeoDataType::LineString(coord_type, dim), + true => NativeType::LargeLineString(coord_type, dim), + false => NativeType::LineString(coord_type, dim), }; fields.push(Field::new("", linestring.to_data_type(), true)); let polygon = match O::IS_LARGE { - true => GeoDataType::LargePolygon(coord_type, dim), - false => GeoDataType::Polygon(coord_type, dim), + true => NativeType::LargePolygon(coord_type, dim), + false => NativeType::Polygon(coord_type, dim), }; fields.push(Field::new("", polygon.to_data_type(), true)); let multi_point = match O::IS_LARGE { - true => GeoDataType::LargeMultiPoint(coord_type, dim), - false => GeoDataType::MultiPoint(coord_type, dim), + true => NativeType::LargeMultiPoint(coord_type, dim), + false => NativeType::MultiPoint(coord_type, dim), }; fields.push(Field::new("", multi_point.to_data_type(), true)); let multi_line_string = match O::IS_LARGE { - true => GeoDataType::LargeMultiLineString(coord_type, dim), - false => GeoDataType::MultiLineString(coord_type, dim), + true => NativeType::LargeMultiLineString(coord_type, dim), + false => NativeType::MultiLineString(coord_type, dim), }; fields.push(Field::new("", multi_line_string.to_data_type(), true)); let multi_polygon = match O::IS_LARGE { - true => GeoDataType::LargeMultiPolygon(coord_type, dim), - false => GeoDataType::MultiPolygon(coord_type, dim), + true => NativeType::LargeMultiPolygon(coord_type, dim), + false => NativeType::MultiPolygon(coord_type, dim), }; fields.push(Field::new("", multi_polygon.to_data_type(), true)); @@ -354,62 +362,58 @@ fn rect_data_type(dim: Dimension) -> DataType { DataType::Struct(rect_fields(dim)) } -impl GeoDataType { +impl NativeType { /// Get the [`CoordType`] of this data type. /// /// Returns None for WKB and LargeWKB - pub fn coord_type(&self) -> Option { - use GeoDataType::*; + pub fn coord_type(&self) -> CoordType { + use NativeType::*; match self { - Point(ct, _) => Some(*ct), - LineString(ct, _) => Some(*ct), - LargeLineString(ct, _) => Some(*ct), - Polygon(ct, _) => Some(*ct), - LargePolygon(ct, _) => Some(*ct), - MultiPoint(ct, _) => Some(*ct), - LargeMultiPoint(ct, _) => Some(*ct), - MultiLineString(ct, _) => Some(*ct), - LargeMultiLineString(ct, _) => Some(*ct), - MultiPolygon(ct, _) => Some(*ct), - LargeMultiPolygon(ct, _) => Some(*ct), - Mixed(ct, _) => Some(*ct), - LargeMixed(ct, _) => Some(*ct), - GeometryCollection(ct, _) => Some(*ct), - LargeGeometryCollection(ct, _) => Some(*ct), - WKB => None, - LargeWKB => None, - Rect(_) => Some(CoordType::Separated), + Point(ct, _) => *ct, + LineString(ct, _) => *ct, + LargeLineString(ct, _) => *ct, + Polygon(ct, _) => *ct, + LargePolygon(ct, _) => *ct, + MultiPoint(ct, _) => *ct, + LargeMultiPoint(ct, _) => *ct, + MultiLineString(ct, _) => *ct, + LargeMultiLineString(ct, _) => *ct, + MultiPolygon(ct, _) => *ct, + LargeMultiPolygon(ct, _) => *ct, + Mixed(ct, _) => *ct, + LargeMixed(ct, _) => *ct, + GeometryCollection(ct, _) => *ct, + LargeGeometryCollection(ct, _) => *ct, + Rect(_) => CoordType::Separated, } } /// Get the [`Dimension`] of this data type. /// /// Returns None for WKB and LargeWKB - pub fn dimension(&self) -> Option { - use GeoDataType::*; + pub fn dimension(&self) -> Dimension { + use NativeType::*; match self { - Point(_, dim) => Some(*dim), - LineString(_, dim) => Some(*dim), - LargeLineString(_, dim) => Some(*dim), - Polygon(_, dim) => Some(*dim), - LargePolygon(_, dim) => Some(*dim), - MultiPoint(_, dim) => Some(*dim), - LargeMultiPoint(_, dim) => Some(*dim), - MultiLineString(_, dim) => Some(*dim), - LargeMultiLineString(_, dim) => Some(*dim), - MultiPolygon(_, dim) => Some(*dim), - LargeMultiPolygon(_, dim) => Some(*dim), - Mixed(_, dim) => Some(*dim), - LargeMixed(_, dim) => Some(*dim), - GeometryCollection(_, dim) => Some(*dim), - LargeGeometryCollection(_, dim) => Some(*dim), - WKB => None, - LargeWKB => None, - Rect(dim) => Some(*dim), + Point(_, dim) => *dim, + LineString(_, dim) => *dim, + LargeLineString(_, dim) => *dim, + Polygon(_, dim) => *dim, + LargePolygon(_, dim) => *dim, + MultiPoint(_, dim) => *dim, + LargeMultiPoint(_, dim) => *dim, + MultiLineString(_, dim) => *dim, + LargeMultiLineString(_, dim) => *dim, + MultiPolygon(_, dim) => *dim, + LargeMultiPolygon(_, dim) => *dim, + Mixed(_, dim) => *dim, + LargeMixed(_, dim) => *dim, + GeometryCollection(_, dim) => *dim, + LargeGeometryCollection(_, dim) => *dim, + Rect(dim) => *dim, } } - /// Converts a [`GeoDataType`] into the relevant arrow [`DataType`]. + /// Converts a [`NativeType`] into the relevant arrow [`DataType`]. /// /// Note that an arrow [`DataType`] will lose the accompanying GeoArrow metadata if it is not /// part of a [`Field`] with GeoArrow extension metadata in its field metadata. @@ -417,14 +421,14 @@ impl GeoDataType { /// # Examples /// /// ``` - /// use geoarrow::{array::CoordType, datatypes::{GeoDataType, Dimension}}; + /// use geoarrow::{array::CoordType, datatypes::{NativeType, Dimension}}; /// use arrow_schema::DataType; /// - /// let data_type = GeoDataType::Point(CoordType::Interleaved, Dimension::XY).to_data_type(); + /// let data_type = NativeType::Point(CoordType::Interleaved, Dimension::XY).to_data_type(); /// assert!(matches!(data_type, DataType::FixedSizeList(_, _))); /// ``` pub fn to_data_type(&self) -> DataType { - use GeoDataType::*; + use NativeType::*; match self { Point(coord_type, dim) => point_data_type(*coord_type, *dim), LineString(coord_type, dim) => line_string_data_type::(*coord_type, *dim), @@ -449,8 +453,6 @@ impl GeoDataType { LargeGeometryCollection(coord_type, dim) => { geometry_collection_data_type::(*coord_type, *dim) } - WKB => wkb_data_type::(), - LargeWKB => wkb_data_type::(), Rect(dim) => rect_data_type(*dim), } } @@ -460,13 +462,13 @@ impl GeoDataType { /// # Examples /// /// ``` - /// use geoarrow::datatypes::GeoDataType; + /// use geoarrow::datatypes::NativeType; /// - /// let geo_data_type = GeoDataType::Point(Default::default(), 2.try_into().unwrap()); + /// let geo_data_type = NativeType::Point(Default::default(), 2.try_into().unwrap()); /// assert_eq!(geo_data_type.extension_name(), "geoarrow.point") /// ``` pub fn extension_name(&self) -> &'static str { - use GeoDataType::*; + use NativeType::*; match self { Point(_, _) => "geoarrow.point", LineString(_, _) | LargeLineString(_, _) => "geoarrow.linestring", @@ -478,20 +480,19 @@ impl GeoDataType { GeometryCollection(_, _) | LargeGeometryCollection(_, _) => { "geoarrow.geometrycollection" } - WKB | LargeWKB => "geoarrow.wkb", Rect(_) => "geoarrow.box", } } - /// Converts this [`GeoDataType`] into an arrow [`Field`], maintaining GeoArrow extension + /// Converts this [`NativeType`] into an arrow [`Field`], maintaining GeoArrow extension /// metadata. /// /// # Examples /// /// ``` - /// use geoarrow::datatypes::GeoDataType; + /// use geoarrow::datatypes::NativeType; /// - /// let geo_data_type = GeoDataType::Point(Default::default(), 2.try_into().unwrap()); + /// let geo_data_type = NativeType::Point(Default::default(), 2.try_into().unwrap()); /// let field = geo_data_type.to_field("geometry", false); /// assert_eq!(field.name(), "geometry"); /// assert!(!field.is_nullable()); @@ -512,9 +513,9 @@ impl GeoDataType { /// # Examples /// /// ``` - /// use geoarrow::{array::metadata::{ArrayMetadata, Edges}, datatypes::GeoDataType}; + /// use geoarrow::{array::metadata::{ArrayMetadata, Edges}, datatypes::NativeType}; /// - /// let geo_data_type = GeoDataType::Point(Default::default(), 2.try_into().unwrap()); + /// let geo_data_type = NativeType::Point(Default::default(), 2.try_into().unwrap()); /// let metadata = ArrayMetadata { /// crs: None, /// edges: Some(Edges::Spherical), @@ -547,13 +548,13 @@ impl GeoDataType { /// # Examples /// /// ``` - /// use geoarrow::{array::CoordType, datatypes::GeoDataType}; + /// use geoarrow::{array::CoordType, datatypes::NativeType}; /// - /// let geo_data_type = GeoDataType::Point(CoordType::Interleaved, 2.try_into().unwrap()); + /// let geo_data_type = NativeType::Point(CoordType::Interleaved, 2.try_into().unwrap()); /// let separated_geo_data_type = geo_data_type.with_coord_type(CoordType::Separated); /// ``` - pub fn with_coord_type(self, coord_type: CoordType) -> GeoDataType { - use GeoDataType::*; + pub fn with_coord_type(self, coord_type: CoordType) -> NativeType { + use NativeType::*; match self { Point(_, dim) => Point(coord_type, dim), LineString(_, dim) => LineString(coord_type, dim), @@ -570,8 +571,6 @@ impl GeoDataType { LargeMixed(_, dim) => LargeMixed(coord_type, dim), GeometryCollection(_, dim) => GeometryCollection(coord_type, dim), LargeGeometryCollection(_, dim) => LargeGeometryCollection(coord_type, dim), - WKB => WKB, - LargeWKB => LargeWKB, Rect(dim) => Rect(dim), } } @@ -581,13 +580,13 @@ impl GeoDataType { /// # Examples /// /// ``` - /// use geoarrow::datatypes::GeoDataType; + /// use geoarrow::datatypes::NativeType; /// - /// let geo_data_type = GeoDataType::Point(Default::default(), 2.try_into().unwrap()); + /// let geo_data_type = NativeType::Point(Default::default(), 2.try_into().unwrap()); /// let geo_data_type_3d = geo_data_type.with_dimension(3.try_into().unwrap()); /// ``` - pub fn with_dimension(self, dim: Dimension) -> GeoDataType { - use GeoDataType::*; + pub fn with_dimension(self, dim: Dimension) -> NativeType { + use NativeType::*; match self { Point(coord_type, _) => Point(coord_type, dim), LineString(coord_type, _) => LineString(coord_type, dim), @@ -604,13 +603,110 @@ impl GeoDataType { LargeMixed(coord_type, _) => LargeMixed(coord_type, dim), GeometryCollection(coord_type, _) => GeometryCollection(coord_type, dim), LargeGeometryCollection(coord_type, _) => LargeGeometryCollection(coord_type, dim), - WKB => WKB, - LargeWKB => LargeWKB, Rect(_) => Rect(dim), } } } +impl SerializedType { + /// Converts a [`SerializedType`] into the relevant arrow [`DataType`]. + /// + /// Note that an arrow [`DataType`] will lose the accompanying GeoArrow metadata if it is not + /// part of a [`Field`] with GeoArrow extension metadata in its field metadata. + pub fn to_data_type(&self) -> DataType { + use SerializedType::*; + match self { + WKB => wkb_data_type::(), + LargeWKB => wkb_data_type::(), + } + } + + /// Returns the GeoArrow extension name pertaining to this data type. + pub fn extension_name(&self) -> &'static str { + use SerializedType::*; + match self { + WKB | LargeWKB => "geoarrow.wkb", + } + } + + /// Converts this [`SerializedType`] into an arrow [`Field`], maintaining GeoArrow extension + /// metadata. + pub fn to_field>(&self, name: N, nullable: bool) -> Field { + let extension_name = self.extension_name(); + let mut metadata = HashMap::with_capacity(1); + metadata.insert( + "ARROW:extension:name".to_string(), + extension_name.to_string(), + ); + Field::new(name, self.to_data_type(), nullable).with_metadata(metadata) + } + + /// Converts this geo-data type to a field with the additional [ArrayMetadata]. + pub fn to_field_with_metadata>( + &self, + name: N, + nullable: bool, + array_metadata: &ArrayMetadata, + ) -> Field { + let extension_name = self.extension_name(); + let mut metadata = HashMap::with_capacity(2); + metadata.insert( + "ARROW:extension:name".to_string(), + extension_name.to_string(), + ); + if array_metadata.should_serialize() { + metadata.insert( + "ARROW:extension:metadata".to_string(), + serde_json::to_string(array_metadata).unwrap(), + ); + } + Field::new(name, self.to_data_type(), nullable).with_metadata(metadata) + } +} + +impl AnyType { + /// Converts a [`AnyType`] into the relevant arrow [`DataType`]. + /// + /// Note that an arrow [`DataType`] will lose the accompanying GeoArrow metadata if it is not + /// part of a [`Field`] with GeoArrow extension metadata in its field metadata. + pub fn to_data_type(&self) -> DataType { + match self { + Self::Native(x) => x.to_data_type(), + Self::Serialized(x) => x.to_data_type(), + } + } + + /// Returns the GeoArrow extension name pertaining to this data type. + pub fn extension_name(&self) -> &'static str { + match self { + Self::Native(x) => x.extension_name(), + Self::Serialized(x) => x.extension_name(), + } + } + + /// Converts this [`SerializedType`] into an arrow [`Field`], maintaining GeoArrow extension + /// metadata. + pub fn to_field>(&self, name: N, nullable: bool) -> Field { + match self { + Self::Native(x) => x.to_field(name, nullable), + Self::Serialized(x) => x.to_field(name, nullable), + } + } + + /// Converts this geo-data type to a field with the additional [ArrayMetadata]. + pub fn to_field_with_metadata>( + &self, + name: N, + nullable: bool, + array_metadata: &ArrayMetadata, + ) -> Field { + match self { + Self::Native(x) => x.to_field_with_metadata(name, nullable, array_metadata), + Self::Serialized(x) => x.to_field_with_metadata(name, nullable, array_metadata), + } + } +} + fn parse_data_type(data_type: &DataType) -> Result<(CoordType, Dimension)> { match data_type { DataType::FixedSizeList(_, list_size) => { @@ -623,34 +719,34 @@ fn parse_data_type(data_type: &DataType) -> Result<(CoordType, Dimension)> { } } -fn parse_point(field: &Field) -> Result { +fn parse_point(field: &Field) -> Result { let (ct, dim) = parse_data_type(field.data_type())?; - Ok(GeoDataType::Point(ct, dim)) + Ok(NativeType::Point(ct, dim)) } -fn parse_linestring(field: &Field) -> Result { +fn parse_linestring(field: &Field) -> Result { match field.data_type() { DataType::List(inner_field) | DataType::LargeList(inner_field) => { let (ct, dim) = parse_data_type(inner_field.data_type())?; - Ok(GeoDataType::LineString(ct, dim)) + Ok(NativeType::LineString(ct, dim)) } dt => Err(GeoArrowError::General(format!("Unexpected data type {dt}"))), } } -fn parse_polygon(field: &Field) -> Result { +fn parse_polygon(field: &Field) -> Result { match field.data_type() { DataType::List(inner1) => match inner1.data_type() { DataType::List(inner2) => { let (ct, dim) = parse_data_type(inner2.data_type())?; - Ok(GeoDataType::Polygon(ct, dim)) + Ok(NativeType::Polygon(ct, dim)) } _ => panic!(), }, DataType::LargeList(inner1) => match inner1.data_type() { DataType::LargeList(inner2) => { let (ct, dim) = parse_data_type(inner2.data_type())?; - Ok(GeoDataType::LargePolygon(ct, dim)) + Ok(NativeType::LargePolygon(ct, dim)) } _ => panic!(), }, @@ -658,33 +754,33 @@ fn parse_polygon(field: &Field) -> Result { } } -fn parse_multi_point(field: &Field) -> Result { +fn parse_multi_point(field: &Field) -> Result { match field.data_type() { DataType::List(inner_field) => { let (ct, dim) = parse_data_type(inner_field.data_type())?; - Ok(GeoDataType::MultiPoint(ct, dim)) + Ok(NativeType::MultiPoint(ct, dim)) } DataType::LargeList(inner_field) => { let (ct, dim) = parse_data_type(inner_field.data_type())?; - Ok(GeoDataType::LargeMultiPoint(ct, dim)) + Ok(NativeType::LargeMultiPoint(ct, dim)) } _ => panic!(), } } -fn parse_multi_linestring(field: &Field) -> Result { +fn parse_multi_linestring(field: &Field) -> Result { match field.data_type() { DataType::List(inner1) => match inner1.data_type() { DataType::List(inner2) => { let (ct, dim) = parse_data_type(inner2.data_type())?; - Ok(GeoDataType::MultiLineString(ct, dim)) + Ok(NativeType::MultiLineString(ct, dim)) } _ => panic!(), }, DataType::LargeList(inner1) => match inner1.data_type() { DataType::LargeList(inner2) => { let (ct, dim) = parse_data_type(inner2.data_type())?; - Ok(GeoDataType::LargeMultiLineString(ct, dim)) + Ok(NativeType::LargeMultiLineString(ct, dim)) } _ => panic!(), }, @@ -692,13 +788,13 @@ fn parse_multi_linestring(field: &Field) -> Result { } } -fn parse_multi_polygon(field: &Field) -> Result { +fn parse_multi_polygon(field: &Field) -> Result { match field.data_type() { DataType::List(inner1) => match inner1.data_type() { DataType::List(inner2) => match inner2.data_type() { DataType::List(inner3) => { let (ct, dim) = parse_data_type(inner3.data_type())?; - Ok(GeoDataType::MultiPolygon(ct, dim)) + Ok(NativeType::MultiPolygon(ct, dim)) } _ => panic!(), }, @@ -708,7 +804,7 @@ fn parse_multi_polygon(field: &Field) -> Result { DataType::LargeList(inner2) => match inner2.data_type() { DataType::LargeList(inner3) => { let (ct, dim) = parse_data_type(inner3.data_type())?; - Ok(GeoDataType::LargeMultiPolygon(ct, dim)) + Ok(NativeType::LargeMultiPolygon(ct, dim)) } _ => panic!(), }, @@ -718,7 +814,7 @@ fn parse_multi_polygon(field: &Field) -> Result { } } -fn parse_geometry(field: &Field) -> Result { +fn parse_geometry(field: &Field) -> Result { match field.data_type() { DataType::Union(fields, _) => { let mut coord_types: HashSet = HashSet::new(); @@ -726,146 +822,146 @@ fn parse_geometry(field: &Field) -> Result { fields.iter().try_for_each(|(type_id, field)| { match type_id { 1 => match parse_point(field)? { - GeoDataType::Point(ct, Dimension::XY) => { + NativeType::Point(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 2 => match parse_linestring(field)? { - GeoDataType::LineString(ct, Dimension::XY) => { + NativeType::LineString(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargeLineString(ct, Dimension::XY) => { + NativeType::LargeLineString(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 3 => match parse_polygon(field)? { - GeoDataType::Polygon(ct, Dimension::XY) => { + NativeType::Polygon(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargePolygon(ct, Dimension::XY) => { + NativeType::LargePolygon(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 4 => match parse_multi_point(field)? { - GeoDataType::MultiPoint(ct, Dimension::XY) => { + NativeType::MultiPoint(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargeMultiPoint(ct, Dimension::XY) => { + NativeType::LargeMultiPoint(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 5 => match parse_multi_linestring(field)? { - GeoDataType::MultiLineString(ct, Dimension::XY) => { + NativeType::MultiLineString(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargeMultiLineString(ct, Dimension::XY) => { + NativeType::LargeMultiLineString(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 6 => match parse_multi_polygon(field)? { - GeoDataType::MultiPolygon(ct, Dimension::XY) => { + NativeType::MultiPolygon(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargeMultiPolygon(ct, Dimension::XY) => { + NativeType::LargeMultiPolygon(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 7 => match parse_geometry_collection(field)? { - GeoDataType::GeometryCollection(ct, Dimension::XY) => { + NativeType::GeometryCollection(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } - GeoDataType::LargeGeometryCollection(ct, Dimension::XY) => { + NativeType::LargeGeometryCollection(ct, Dimension::XY) => { coord_types.insert(ct); dimensions.insert(Dimension::XY); } _ => unreachable!(), }, 11 => match parse_point(field)? { - GeoDataType::Point(ct, Dimension::XYZ) => { + NativeType::Point(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 12 => match parse_linestring(field)? { - GeoDataType::LineString(ct, Dimension::XYZ) => { + NativeType::LineString(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargeLineString(ct, Dimension::XYZ) => { + NativeType::LargeLineString(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 13 => match parse_polygon(field)? { - GeoDataType::Polygon(ct, Dimension::XYZ) => { + NativeType::Polygon(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargePolygon(ct, Dimension::XYZ) => { + NativeType::LargePolygon(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 14 => match parse_multi_point(field)? { - GeoDataType::MultiPoint(ct, Dimension::XYZ) => { + NativeType::MultiPoint(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargeMultiPoint(ct, Dimension::XYZ) => { + NativeType::LargeMultiPoint(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 15 => match parse_multi_linestring(field)? { - GeoDataType::MultiLineString(ct, Dimension::XYZ) => { + NativeType::MultiLineString(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargeMultiLineString(ct, Dimension::XYZ) => { + NativeType::LargeMultiLineString(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 16 => match parse_multi_polygon(field)? { - GeoDataType::MultiPolygon(ct, Dimension::XYZ) => { + NativeType::MultiPolygon(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargeMultiPolygon(ct, Dimension::XYZ) => { + NativeType::LargeMultiPolygon(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } _ => unreachable!(), }, 17 => match parse_geometry_collection(field)? { - GeoDataType::GeometryCollection(ct, Dimension::XYZ) => { + NativeType::GeometryCollection(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } - GeoDataType::LargeGeometryCollection(ct, Dimension::XYZ) => { + NativeType::LargeGeometryCollection(ct, Dimension::XYZ) => { coord_types.insert(ct); dimensions.insert(Dimension::XYZ); } @@ -889,25 +985,25 @@ fn parse_geometry(field: &Field) -> Result { let coord_type = coord_types.drain().next().unwrap(); let dimension = dimensions.drain().next().unwrap(); - Ok(GeoDataType::Mixed(coord_type, dimension)) + Ok(NativeType::Mixed(coord_type, dimension)) } _ => panic!("Unexpected data type"), } } -fn parse_geometry_collection(field: &Field) -> Result { +fn parse_geometry_collection(field: &Field) -> Result { // We need to parse the _inner_ type of the geometry collection as a union so that we can check // what coordinate type it's using. match field.data_type() { DataType::List(inner_field) => match parse_geometry(inner_field)? { - GeoDataType::Mixed(coord_type, dim) => { - Ok(GeoDataType::GeometryCollection(coord_type, dim)) + NativeType::Mixed(coord_type, dim) => { + Ok(NativeType::GeometryCollection(coord_type, dim)) } _ => panic!(), }, DataType::LargeList(inner_field) => match parse_geometry(inner_field)? { - GeoDataType::LargeMixed(coord_type, dim) => { - Ok(GeoDataType::LargeGeometryCollection(coord_type, dim)) + NativeType::LargeMixed(coord_type, dim) => { + Ok(NativeType::LargeGeometryCollection(coord_type, dim)) } _ => panic!(), }, @@ -915,26 +1011,26 @@ fn parse_geometry_collection(field: &Field) -> Result { } } -fn parse_wkb(field: &Field) -> GeoDataType { +fn parse_wkb(field: &Field) -> SerializedType { match field.data_type() { - DataType::Binary => GeoDataType::WKB, - DataType::LargeBinary => GeoDataType::LargeWKB, + DataType::Binary => SerializedType::WKB, + DataType::LargeBinary => SerializedType::LargeWKB, _ => panic!(), } } -fn parse_rect(field: &Field) -> GeoDataType { +fn parse_rect(field: &Field) -> NativeType { match field.data_type() { DataType::Struct(struct_fields) => match struct_fields.len() { - 4 => GeoDataType::Rect(Dimension::XY), - 6 => GeoDataType::Rect(Dimension::XYZ), + 4 => NativeType::Rect(Dimension::XY), + 6 => NativeType::Rect(Dimension::XYZ), _ => panic!("unexpected number of struct fields"), }, _ => panic!("unexpected data type parsing rect"), } } -impl TryFrom<&Field> for GeoDataType { +impl TryFrom<&Field> for NativeType { type Error = GeoArrowError; fn try_from(field: &Field) -> Result { @@ -948,7 +1044,6 @@ impl TryFrom<&Field> for GeoDataType { "geoarrow.multipolygon" => parse_multi_polygon(field)?, "geoarrow.geometry" => parse_geometry(field)?, "geoarrow.geometrycollection" => parse_geometry_collection(field)?, - "geoarrow.wkb" | "ogc.wkb" => parse_wkb(field), "geoarrow.box" => parse_rect(field), name => { return Err(GeoArrowError::General(format!( @@ -963,21 +1058,15 @@ impl TryFrom<&Field> for GeoDataType { // metadata should use TryFrom for a specific geometry type directly, instead of using // GeometryArray let data_type = match field.data_type() { - DataType::Binary => { - GeoDataType::WKB - } - DataType::LargeBinary => { - GeoDataType::LargeWKB - } DataType::Struct(struct_fields) => { match struct_fields.len() { - 2 => GeoDataType::Point(CoordType::Separated, Dimension::XY), - 3 => GeoDataType::Point(CoordType::Separated, Dimension::XYZ), + 2 => NativeType::Point(CoordType::Separated, Dimension::XY), + 3 => NativeType::Point(CoordType::Separated, Dimension::XYZ), l => return Err(GeoArrowError::General(format!("incorrect number of struct fields {l}") )) } } DataType::FixedSizeList(_, list_size) => { - GeoDataType::Point(CoordType::Interleaved, (*list_size as usize).try_into()?) + NativeType::Point(CoordType::Interleaved, (*list_size as usize).try_into()?) } _ => return Err(GeoArrowError::General("Only Binary, LargeBinary, FixedSizeList, and Struct arrays are unambigously typed and can be used without extension metadata.".to_string())) }; @@ -986,22 +1075,67 @@ impl TryFrom<&Field> for GeoDataType { } } +impl TryFrom<&Field> for SerializedType { + type Error = GeoArrowError; + + fn try_from(field: &Field) -> Result { + if let Some(extension_name) = field.metadata().get("ARROW:extension:name") { + let data_type = match extension_name.as_str() { + "geoarrow.wkb" | "ogc.wkb" => parse_wkb(field), + name => { + return Err(GeoArrowError::General(format!( + "Unexpected extension name {}", + name + ))) + } + }; + Ok(data_type) + } else { + // TODO: better error here, and document that arrays without geoarrow extension + // metadata should use TryFrom for a specific geometry type directly, instead of using + // GeometryArray + let data_type = match field.data_type() { + DataType::Binary => { + SerializedType::WKB + } + DataType::LargeBinary => { + SerializedType::LargeWKB + } + _ => return Err(GeoArrowError::General("Only Binary, LargeBinary, FixedSizeList, and Struct arrays are unambigously typed and can be used without extension metadata.".to_string())) + }; + Ok(data_type) + } + } +} + +impl TryFrom<&Field> for AnyType { + type Error = GeoArrowError; + + fn try_from(value: &Field) -> std::result::Result { + if let Ok(t) = NativeType::try_from(value) { + Ok(AnyType::Native(t)) + } else { + Ok(AnyType::Serialized(value.try_into()?)) + } + } +} + #[cfg(test)] mod test { use super::*; use crate::array::MixedGeometryBuilder; - use crate::NativeArray; + use crate::{ArrayBase, NativeArray}; #[test] - fn geodatatype_round_trip() { + fn native_type_round_trip() { let point_array = crate::test::point::point_array(); let field = point_array.extension_field(); - let data_type: GeoDataType = field.as_ref().try_into().unwrap(); + let data_type: NativeType = field.as_ref().try_into().unwrap(); assert_eq!(point_array.data_type(), data_type); let ml_array = crate::test::multilinestring::ml_array(); let field = ml_array.extension_field(); - let data_type: GeoDataType = field.as_ref().try_into().unwrap(); + let data_type: NativeType = field.as_ref().try_into().unwrap(); assert_eq!(ml_array.data_type(), data_type); let mut builder = MixedGeometryBuilder::::new(); @@ -1016,7 +1150,7 @@ mod test { .unwrap(); let mixed_array = builder.finish(); let field = mixed_array.extension_field(); - let data_type: GeoDataType = field.as_ref().try_into().unwrap(); + let data_type: NativeType = field.as_ref().try_into().unwrap(); assert_eq!(mixed_array.data_type(), data_type); } } diff --git a/src/indexed/array.rs b/src/indexed/array.rs index 703ac40b7..5ac7664cb 100644 --- a/src/indexed/array.rs +++ b/src/indexed/array.rs @@ -2,10 +2,10 @@ use std::sync::Arc; use crate::algorithm::geo_index::RTree; use crate::array::*; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{CoordTrait, RectTrait}; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::builder::BooleanBuilder; use arrow_array::BooleanArray; @@ -31,7 +31,7 @@ impl IndexedGeometryArray { } #[allow(dead_code)] - pub fn data_type(&self) -> GeoDataType { + pub fn data_type(&self) -> NativeType { self.array.data_type() } @@ -56,7 +56,7 @@ impl IndexedGeometryArray { } } -impl<'a, G: NativeArray + NativeArrayAccessor<'a>> IndexedGeometryArray { +impl<'a, G: NativeArray + ArrayAccessor<'a>> IndexedGeometryArray { /// Intended for e.g. intersects against a scalar with a single bounding box pub fn unary_boolean(&'a self, rhs_rect: &impl RectTrait, op: F) -> BooleanArray where @@ -91,7 +91,7 @@ impl<'a, G: NativeArray + NativeArrayAccessor<'a>> IndexedGeometryArray { op: F, ) -> Result where - G2: NativeArray + NativeArrayAccessor<'a>, + G2: NativeArray + ArrayAccessor<'a>, F: Fn(G::Item, G2::Item) -> Result, { if self.len() != other.len() { diff --git a/src/io/display/array.rs b/src/io/display/array.rs index 4873da4b7..3f358e0fd 100644 --- a/src/io/display/array.rs +++ b/src/io/display/array.rs @@ -4,7 +4,7 @@ use arrow_array::OffsetSizeTrait; use crate::array::*; use crate::io::display::scalar::write_geometry; -use crate::trait_::{NativeArrayAccessor, NativeScalar}; +use crate::trait_::{ArrayAccessor, NativeScalar}; use crate::NativeArray; pub(crate) fn indent(f: &mut fmt::Formatter<'_>, indented_spaces: usize) -> fmt::Result { diff --git a/src/io/display/chunked_array.rs b/src/io/display/chunked_array.rs index a10bc3cbc..13d0cc98a 100644 --- a/src/io/display/chunked_array.rs +++ b/src/io/display/chunked_array.rs @@ -101,7 +101,7 @@ impl_fmt_generic!( ChunkedGeometryCollectionArray, "ChunkedGeometryCollectionArray" ); -impl_fmt_generic!(ChunkedWKBArray, "ChunkedWKBArray"); +// impl_fmt_generic!(ChunkedWKBArray, "ChunkedWKBArray"); #[cfg(test)] mod test { diff --git a/src/io/display/scalar.rs b/src/io/display/scalar.rs index f154e5c3e..72fa653fb 100644 --- a/src/io/display/scalar.rs +++ b/src/io/display/scalar.rs @@ -86,7 +86,7 @@ mod test { use crate::array::PointArray; use crate::io::wkb::ToWKB; use crate::test::{multipolygon, point}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use crate::NativeArray; #[test] diff --git a/src/io/geos/array/linestring.rs b/src/io/geos/array/linestring.rs index a1fd9729f..8c9944bea 100644 --- a/src/io/geos/array/linestring.rs +++ b/src/io/geos/array/linestring.rs @@ -35,7 +35,7 @@ impl TryFrom>> mod test { use super::*; use crate::test::linestring::ls_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/array/multilinestring.rs b/src/io/geos/array/multilinestring.rs index 7d6194dd6..f8f58ffaf 100644 --- a/src/io/geos/array/multilinestring.rs +++ b/src/io/geos/array/multilinestring.rs @@ -35,7 +35,7 @@ impl TryFrom>> mod test { use super::*; use crate::test::multilinestring::ml_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/array/multipoint.rs b/src/io/geos/array/multipoint.rs index cd3b3c4ec..02c64691b 100644 --- a/src/io/geos/array/multipoint.rs +++ b/src/io/geos/array/multipoint.rs @@ -35,7 +35,7 @@ impl TryFrom>> mod test { use super::*; use crate::test::multipoint::mp_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/array/multipolygon.rs b/src/io/geos/array/multipolygon.rs index e32cf015f..8ed167768 100644 --- a/src/io/geos/array/multipolygon.rs +++ b/src/io/geos/array/multipolygon.rs @@ -35,7 +35,7 @@ impl TryFrom>> mod test { use super::*; use crate::test::multipolygon::mp_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/array/point.rs b/src/io/geos/array/point.rs index f0bc18159..cc9c85571 100644 --- a/src/io/geos/array/point.rs +++ b/src/io/geos/array/point.rs @@ -28,7 +28,7 @@ impl TryFrom>> for PointArray { mod test { use super::*; use crate::test::point::point_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/array/polygon.rs b/src/io/geos/array/polygon.rs index 131fb2855..654a60aef 100644 --- a/src/io/geos/array/polygon.rs +++ b/src/io/geos/array/polygon.rs @@ -36,7 +36,7 @@ impl TryFrom>> mod test { use super::*; use crate::test::polygon::p_array; - use crate::trait_::{NativeArrayAccessor, NativeScalar}; + use crate::trait_::{ArrayAccessor, NativeScalar}; #[test] fn geos_round_trip() { diff --git a/src/io/geos/scalar/point.rs b/src/io/geos/scalar/point.rs index 88a0b791e..e1da9b5b8 100644 --- a/src/io/geos/scalar/point.rs +++ b/src/io/geos/scalar/point.rs @@ -310,7 +310,7 @@ mod test { use super::*; use crate::algorithm::native::eq::point_eq; use crate::test::point; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; #[test] fn round_trip_point() { diff --git a/src/io/geozero/api/wkt.rs b/src/io/geozero/api/wkt.rs index eeed47d3a..d61064f0c 100644 --- a/src/io/geozero/api/wkt.rs +++ b/src/io/geozero/api/wkt.rs @@ -137,8 +137,8 @@ impl FromWKT for Arc { #[cfg(test)] mod test { - use crate::datatypes::{Dimension, GeoDataType}; - use crate::trait_::NativeArrayAccessor; + use crate::datatypes::{Dimension, NativeType}; + use crate::trait_::ArrayAccessor; use arrow_array::builder::StringBuilder; use super::*; @@ -183,7 +183,7 @@ mod test { let geom_arr = geom_arr.downcast(true); assert!(matches!( geom_arr.data_type(), - GeoDataType::Point(_, Dimension::XY) + NativeType::Point(_, Dimension::XY) )); } } diff --git a/src/io/geozero/array/dynamic.rs b/src/io/geozero/array/dynamic.rs index 730031a1d..c11364184 100644 --- a/src/io/geozero/array/dynamic.rs +++ b/src/io/geozero/array/dynamic.rs @@ -2,7 +2,7 @@ use geozero::{GeomProcessor, GeozeroGeometry}; use crate::array::dynamic::NativeArrayDyn; use crate::array::AsNativeArray; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; impl GeozeroGeometry for NativeArrayDyn { fn process_geom(&self, processor: &mut P) -> geozero::error::Result<()> @@ -21,7 +21,7 @@ impl GeozeroGeometry for NativeArrayDyn { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.0.data_type() { Point(_, XY) => impl_process!(as_point, 2), @@ -92,7 +92,7 @@ mod test { use super::*; use crate::array::PointArray; use crate::test::point; - use crate::NativeArray; + use crate::ArrayBase; #[test] fn test() { diff --git a/src/io/geozero/array/geometrycollection.rs b/src/io/geozero/array/geometrycollection.rs index 603607a3d..bae1ebec2 100644 --- a/src/io/geozero/array/geometrycollection.rs +++ b/src/io/geozero/array/geometrycollection.rs @@ -1,7 +1,7 @@ use crate::array::GeometryCollectionArray; use crate::io::geozero::scalar::process_geometry_collection; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::OffsetSizeTrait; use geozero::{GeomProcessor, GeozeroGeometry}; diff --git a/src/io/geozero/array/linestring.rs b/src/io/geozero/array/linestring.rs index 374920317..23ab02642 100644 --- a/src/io/geozero/array/linestring.rs +++ b/src/io/geozero/array/linestring.rs @@ -4,8 +4,8 @@ use geozero::{GeomProcessor, GeozeroGeometry}; use crate::array::linestring::LineStringCapacity; use crate::array::{LineStringArray, LineStringBuilder}; use crate::io::geozero::scalar::process_line_string; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; impl GeozeroGeometry for LineStringArray { fn process_geom(&self, processor: &mut P) -> geozero::error::Result<()> @@ -87,7 +87,7 @@ impl GeomProcessor for LineStringBuilder GeozeroGeometry for MultiLineStringArray { fn process_geom(&self, processor: &mut P) -> geozero::error::Result<()> @@ -115,7 +115,7 @@ impl GeomProcessor for MultiLineStringBuilde mod test { use super::*; use crate::test::multilinestring::{ml0, ml1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geo::Geometry; use geozero::error::Result; use geozero::ToWkt; diff --git a/src/io/geozero/array/multipoint.rs b/src/io/geozero/array/multipoint.rs index 218043ae2..f6762f5be 100644 --- a/src/io/geozero/array/multipoint.rs +++ b/src/io/geozero/array/multipoint.rs @@ -1,8 +1,8 @@ use crate::array::multipoint::MultiPointCapacity; use crate::array::{MultiPointArray, MultiPointBuilder}; use crate::io::geozero::scalar::process_multi_point; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::OffsetSizeTrait; use geozero::{GeomProcessor, GeozeroGeometry}; @@ -87,7 +87,7 @@ impl GeomProcessor for MultiPointBuilder GeozeroGeometry for MultiPolygonArray { fn process_geom(&self, processor: &mut P) -> geozero::error::Result<()> @@ -132,7 +132,7 @@ impl GeomProcessor for MultiPolygonBuilder GeozeroGeometry for PointArray { @@ -163,7 +163,7 @@ impl GeomProcessor for PointBuilder { mod test { use super::*; use crate::array::PointArray; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geo::{line_string, point, Geometry, GeometryCollection, LineString, Point}; fn p0() -> Point { diff --git a/src/io/geozero/array/polygon.rs b/src/io/geozero/array/polygon.rs index 46cbc9fb6..0bbf2507d 100644 --- a/src/io/geozero/array/polygon.rs +++ b/src/io/geozero/array/polygon.rs @@ -1,8 +1,8 @@ use crate::array::polygon::PolygonCapacity; use crate::array::{PolygonArray, PolygonBuilder}; use crate::io::geozero::scalar::process_polygon; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::OffsetSizeTrait; use geozero::{GeomProcessor, GeozeroGeometry}; @@ -106,7 +106,7 @@ impl GeomProcessor for PolygonBuilder mod test { use super::*; use crate::test::polygon::{p0, p1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geo::Geometry; use geozero::error::Result; use geozero::ToWkt; diff --git a/src/io/geozero/scalar/geometry.rs b/src/io/geozero/scalar/geometry.rs index dc99a8d49..aa683f212 100644 --- a/src/io/geozero/scalar/geometry.rs +++ b/src/io/geozero/scalar/geometry.rs @@ -8,8 +8,8 @@ use crate::io::geozero::scalar::point::process_point; use crate::io::geozero::scalar::polygon::process_polygon; use crate::io::geozero::ToMixedArray; use crate::scalar::{Geometry, OwnedGeometry}; -use crate::trait_::NativeArrayAccessor; -use crate::NativeArray; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::OffsetSizeTrait; use geozero::{GeomProcessor, GeozeroGeometry}; diff --git a/src/io/geozero/scalar/geometry_array.rs b/src/io/geozero/scalar/geometry_array.rs index fc931874b..407b20f82 100644 --- a/src/io/geozero/scalar/geometry_array.rs +++ b/src/io/geozero/scalar/geometry_array.rs @@ -1,5 +1,5 @@ use crate::array::AsNativeArray; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::io::geozero::scalar::geometry_collection::process_geometry_collection; use crate::io::geozero::scalar::linestring::process_line_string; use crate::io::geozero::scalar::multilinestring::process_multi_line_string; @@ -9,7 +9,7 @@ use crate::io::geozero::scalar::point::process_point; use crate::io::geozero::scalar::polygon::process_polygon; use crate::io::geozero::scalar::process_geometry; use crate::scalar::GeometryScalar; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use geozero::{GeomProcessor, GeozeroGeometry}; pub fn process_geometry_scalar_array( @@ -36,7 +36,7 @@ pub fn process_geometry_scalar_array( } use Dimension::*; - use GeoDataType::*; + use NativeType::*; match geom.data_type() { Point(_, XY) => impl_process!(process_point, as_point, 2), @@ -85,18 +85,18 @@ pub fn process_geometry_scalar_array( LargeGeometryCollection(_, XYZ) => { impl_process!(process_geometry_collection, as_large_geometry_collection, 3) } - WKB => { - let arr = &geom.inner().as_ref(); - let wkb_arr = arr.as_wkb().value(0); - let wkb_object = wkb_arr.to_wkb_object(); - process_geometry(&wkb_object, geom_idx, processor) - } - LargeWKB => { - let arr = &geom.inner().as_ref(); - let wkb_arr = arr.as_large_wkb().value(0); - let wkb_object = wkb_arr.to_wkb_object(); - process_geometry(&wkb_object, geom_idx, processor) - } + // WKB => { + // let arr = &geom.inner().as_ref(); + // let wkb_arr = arr.as_wkb().value(0); + // let wkb_object = wkb_arr.to_wkb_object(); + // process_geometry(&wkb_object, geom_idx, processor) + // } + // LargeWKB => { + // let arr = &geom.inner().as_ref(); + // let wkb_arr = arr.as_large_wkb().value(0); + // let wkb_object = wkb_arr.to_wkb_object(); + // process_geometry(&wkb_object, geom_idx, processor) + // } Rect(_) => todo!(), } } diff --git a/src/io/geozero/table/data_source.rs b/src/io/geozero/table/data_source.rs index 4fcd48a56..92bc0ff84 100644 --- a/src/io/geozero/table/data_source.rs +++ b/src/io/geozero/table/data_source.rs @@ -4,7 +4,7 @@ use std::str::FromStr; use std::sync::Arc; use crate::array::{from_arrow_array, AsNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::io::geozero::scalar::{ process_geometry, process_geometry_collection, process_line_string, process_multi_line_string, process_multi_point, process_multi_polygon, process_point, process_polygon, @@ -13,7 +13,7 @@ use crate::io::geozero::table::json_encoder::{make_encoder, EncoderOptions}; use crate::io::stream::RecordBatchReader; use crate::schema::GeoSchemaExt; use crate::table::Table; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow::array::AsArray; use arrow::datatypes::*; @@ -367,7 +367,7 @@ fn process_geometry_n( ) -> Result<(), GeozeroError> { let arr = geometry_column.as_ref(); let i = within_batch_row_idx; - use GeoDataType::*; + use NativeType::*; match arr.data_type() { Point(_, Dimension::XY) => { let geom = arr.as_point::<2>().value(i); @@ -489,14 +489,14 @@ fn process_geometry_n( let geom = arr.as_large_geometry_collection::<3>().value(i); process_geometry_collection(&geom, 0, processor)?; } - WKB => { - let geom = arr.as_wkb().value(i); - process_geometry(&geom.to_wkb_object(), 0, processor)?; - } - LargeWKB => { - let geom = arr.as_large_wkb().value(i); - process_geometry(&geom.to_wkb_object(), 0, processor)?; - } + // WKB => { + // let geom = arr.as_wkb().value(i); + // process_geometry(&geom.to_wkb_object(), 0, processor)?; + // } + // LargeWKB => { + // let geom = arr.as_large_wkb().value(i); + // process_geometry(&geom.to_wkb_object(), 0, processor)?; + // } Rect(_) => { todo!("process rect") // let geom = arr.as_ref().as_rect::<2>().value(i); diff --git a/src/io/parquet/metadata.rs b/src/io/parquet/metadata.rs index 3ede39106..6cc243aad 100644 --- a/src/io/parquet/metadata.rs +++ b/src/io/parquet/metadata.rs @@ -6,7 +6,7 @@ use std::str::FromStr; use crate::array::metadata::{ArrayMetadata, Edges}; use crate::array::CoordType; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::io::parquet::GeoParquetWriterEncoding; @@ -48,23 +48,23 @@ impl GeoParquetColumnEncoding { /// Construct a new column encoding based on the user's desired encoding pub(crate) fn try_new( writer_encoding: GeoParquetWriterEncoding, - data_type: &GeoDataType, + data_type: &NativeType, ) -> Result { let new_encoding = match writer_encoding { GeoParquetWriterEncoding::WKB => Self::WKB, GeoParquetWriterEncoding::Native => match data_type { - GeoDataType::Point(_, _) => Self::Point, - GeoDataType::LineString(_, _) | GeoDataType::LargeLineString(_, _) => { + NativeType::Point(_, _) => Self::Point, + NativeType::LineString(_, _) | NativeType::LargeLineString(_, _) => { Self::LineString } - GeoDataType::Polygon(_, _) | GeoDataType::LargePolygon(_, _) => Self::Polygon, - GeoDataType::MultiPoint(_, _) | GeoDataType::LargeMultiPoint(_, _) => { + NativeType::Polygon(_, _) | NativeType::LargePolygon(_, _) => Self::Polygon, + NativeType::MultiPoint(_, _) | NativeType::LargeMultiPoint(_, _) => { Self::MultiPoint } - GeoDataType::MultiLineString(_, _) | GeoDataType::LargeMultiLineString(_, _) => { + NativeType::MultiLineString(_, _) | NativeType::LargeMultiLineString(_, _) => { Self::MultiLineString } - GeoDataType::MultiPolygon(_, _) | GeoDataType::LargeMultiPolygon(_, _) => { + NativeType::MultiPolygon(_, _) | NativeType::LargeMultiPolygon(_, _) => { Self::MultiPolygon } dt => { @@ -677,27 +677,27 @@ impl From<&GeoParquetColumnMetadata> for ArrayMetadata { pub(crate) fn infer_geo_data_type( geometry_types: &HashSet, coord_type: CoordType, -) -> Result> { +) -> Result> { use GeoParquetGeometryType::*; match geometry_types.len() { // TODO: for unknown geometry type, should we leave it as WKB? 0 => Ok(None), 1 => Ok(Some(match *geometry_types.iter().next().unwrap() { - Point => GeoDataType::Point(coord_type, Dimension::XY), - LineString => GeoDataType::LineString(coord_type, Dimension::XY), - Polygon => GeoDataType::Polygon(coord_type, Dimension::XY), - MultiPoint => GeoDataType::MultiPoint(coord_type, Dimension::XY), - MultiLineString => GeoDataType::MultiLineString(coord_type, Dimension::XY), - MultiPolygon => GeoDataType::MultiPolygon(coord_type, Dimension::XY), - GeometryCollection => GeoDataType::GeometryCollection(coord_type, Dimension::XY), - PointZ => GeoDataType::Point(coord_type, Dimension::XYZ), - LineStringZ => GeoDataType::LineString(coord_type, Dimension::XYZ), - PolygonZ => GeoDataType::Polygon(coord_type, Dimension::XYZ), - MultiPointZ => GeoDataType::MultiPoint(coord_type, Dimension::XYZ), - MultiLineStringZ => GeoDataType::MultiLineString(coord_type, Dimension::XYZ), - MultiPolygonZ => GeoDataType::MultiPolygon(coord_type, Dimension::XYZ), - GeometryCollectionZ => GeoDataType::GeometryCollection(coord_type, Dimension::XYZ), + Point => NativeType::Point(coord_type, Dimension::XY), + LineString => NativeType::LineString(coord_type, Dimension::XY), + Polygon => NativeType::Polygon(coord_type, Dimension::XY), + MultiPoint => NativeType::MultiPoint(coord_type, Dimension::XY), + MultiLineString => NativeType::MultiLineString(coord_type, Dimension::XY), + MultiPolygon => NativeType::MultiPolygon(coord_type, Dimension::XY), + GeometryCollection => NativeType::GeometryCollection(coord_type, Dimension::XY), + PointZ => NativeType::Point(coord_type, Dimension::XYZ), + LineStringZ => NativeType::LineString(coord_type, Dimension::XYZ), + PolygonZ => NativeType::Polygon(coord_type, Dimension::XYZ), + MultiPointZ => NativeType::MultiPoint(coord_type, Dimension::XYZ), + MultiLineStringZ => NativeType::MultiLineString(coord_type, Dimension::XYZ), + MultiPolygonZ => NativeType::MultiPolygon(coord_type, Dimension::XYZ), + GeometryCollectionZ => NativeType::GeometryCollection(coord_type, Dimension::XYZ), })), _ => { // Check if we can cast to MultiPoint @@ -710,7 +710,7 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == point_count { - return Ok(Some(GeoDataType::MultiPoint(coord_type, Dimension::XY))); + return Ok(Some(NativeType::MultiPoint(coord_type, Dimension::XY))); } // Check if we can cast to MultiPointZ @@ -722,7 +722,7 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == point_count { - return Ok(Some(GeoDataType::MultiPoint(coord_type, Dimension::XYZ))); + return Ok(Some(NativeType::MultiPoint(coord_type, Dimension::XYZ))); } // Check if we can cast to MultiLineString @@ -735,10 +735,7 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == linestring_count { - return Ok(Some(GeoDataType::MultiLineString( - coord_type, - Dimension::XY, - ))); + return Ok(Some(NativeType::MultiLineString(coord_type, Dimension::XY))); } // Check if we can cast to MultiLineStringZ @@ -750,7 +747,7 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == linestring_count { - return Ok(Some(GeoDataType::MultiLineString( + return Ok(Some(NativeType::MultiLineString( coord_type, Dimension::XYZ, ))); @@ -766,7 +763,7 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == polygon_count { - return Ok(Some(GeoDataType::MultiPolygon(coord_type, Dimension::XY))); + return Ok(Some(NativeType::MultiPolygon(coord_type, Dimension::XY))); } // Check if we can cast to MultiPolygonZ @@ -778,24 +775,24 @@ pub(crate) fn infer_geo_data_type( } if geometry_types.len() == polygon_count { - return Ok(Some(GeoDataType::MultiPolygon(coord_type, Dimension::XYZ))); + return Ok(Some(NativeType::MultiPolygon(coord_type, Dimension::XYZ))); } if geometry_types.iter().any(|t| t.has_z()) { - Ok(Some(GeoDataType::Mixed(coord_type, Dimension::XYZ))) + Ok(Some(NativeType::Mixed(coord_type, Dimension::XYZ))) } else { - Ok(Some(GeoDataType::Mixed(coord_type, Dimension::XY))) + Ok(Some(NativeType::Mixed(coord_type, Dimension::XY))) } } } } -/// Find all geometry columns in the Arrow schema, constructing their GeoDataTypes +/// Find all geometry columns in the Arrow schema, constructing their NativeTypes pub(crate) fn find_geoparquet_geom_columns( metadata: &FileMetaData, schema: &Schema, coord_type: CoordType, -) -> Result)>> { +) -> Result)>> { let meta = GeoParquetMetadata::from_parquet_meta(metadata)?; meta.columns diff --git a/src/io/parquet/reader/parse.rs b/src/io/parquet/reader/parse.rs index 774b5ec76..cc8f91c93 100644 --- a/src/io/parquet/reader/parse.rs +++ b/src/io/parquet/reader/parse.rs @@ -7,17 +7,17 @@ use arrow_array::{Array, ArrayRef, RecordBatch}; use arrow_schema::{DataType, Field, FieldRef, Schema, SchemaRef}; use crate::array::{ - from_arrow_array, CoordType, LineStringArray, MultiLineStringArray, MultiPointArray, - MultiPolygonArray, PointArray, PolygonArray, WKBArray, + CoordType, LineStringArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, + PointArray, PolygonArray, WKBArray, }; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{AnyType, Dimension, NativeType, SerializedType}; use crate::error::{GeoArrowError, Result}; use crate::io::parquet::metadata::{ infer_geo_data_type, GeoParquetColumnEncoding, GeoParquetColumnMetadata, GeoParquetGeometryType, GeoParquetMetadata, }; use crate::io::wkb::from_wkb; -use crate::NativeArray; +use crate::ArrayBase; pub fn infer_target_schema( existing_schema: &Schema, @@ -46,7 +46,7 @@ fn infer_target_field( column_meta: &GeoParquetColumnMetadata, coord_type: CoordType, ) -> Result { - let target_geo_data_type: GeoDataType = match column_meta.encoding { + let target_geo_data_type: NativeType = match column_meta.encoding { GeoParquetColumnEncoding::WKB => { infer_target_wkb_type(&column_meta.geometry_types, coord_type)? } @@ -55,9 +55,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::PointZ) { - GeoDataType::Point(CoordType::Separated, Dimension::XYZ) + NativeType::Point(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::Point(CoordType::Separated, Dimension::XY) + NativeType::Point(CoordType::Separated, Dimension::XY) } } GeoParquetColumnEncoding::LineString => { @@ -65,9 +65,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::LineStringZ) { - GeoDataType::LineString(CoordType::Separated, Dimension::XYZ) + NativeType::LineString(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::LineString(CoordType::Separated, Dimension::XY) + NativeType::LineString(CoordType::Separated, Dimension::XY) } } GeoParquetColumnEncoding::Polygon => { @@ -75,9 +75,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::LineStringZ) { - GeoDataType::Polygon(CoordType::Separated, Dimension::XYZ) + NativeType::Polygon(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::Polygon(CoordType::Separated, Dimension::XY) + NativeType::Polygon(CoordType::Separated, Dimension::XY) } } GeoParquetColumnEncoding::MultiPoint => { @@ -88,9 +88,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::MultiPointZ) { - GeoDataType::MultiPoint(CoordType::Separated, Dimension::XYZ) + NativeType::MultiPoint(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::MultiPoint(CoordType::Separated, Dimension::XY) + NativeType::MultiPoint(CoordType::Separated, Dimension::XY) } } GeoParquetColumnEncoding::MultiLineString => { @@ -101,9 +101,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::MultiLineStringZ) { - GeoDataType::MultiLineString(CoordType::Separated, Dimension::XYZ) + NativeType::MultiLineString(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::MultiLineString(CoordType::Separated, Dimension::XY) + NativeType::MultiLineString(CoordType::Separated, Dimension::XY) } } GeoParquetColumnEncoding::MultiPolygon => { @@ -114,9 +114,9 @@ fn infer_target_field( .geometry_types .contains(&GeoParquetGeometryType::MultiPolygonZ) { - GeoDataType::MultiPolygon(CoordType::Separated, Dimension::XYZ) + NativeType::MultiPolygon(CoordType::Separated, Dimension::XYZ) } else { - GeoDataType::MultiPolygon(CoordType::Separated, Dimension::XY) + NativeType::MultiPolygon(CoordType::Separated, Dimension::XY) } } }; @@ -130,9 +130,9 @@ fn infer_target_field( fn infer_target_wkb_type( geometry_types: &HashSet, coord_type: CoordType, -) -> Result { +) -> Result { Ok(infer_geo_data_type(geometry_types, coord_type)? - .unwrap_or(GeoDataType::Mixed(coord_type, Dimension::XY))) + .unwrap_or(NativeType::Mixed(coord_type, Dimension::XY))) } /// Parse a record batch to a GeoArrow record batch. @@ -170,38 +170,47 @@ fn parse_array( orig_field: &Field, target_field: &Field, ) -> Result> { - use GeoDataType::*; - let geo_arr = from_arrow_array(array.as_ref(), orig_field)?; - let target_geo_data_type: GeoDataType = target_field.try_into()?; - let arr = array.as_ref(); - use Dimension::*; - match geo_arr.data_type() { - WKB | LargeWKB => parse_wkb_column(arr, target_geo_data_type), - Point(_, XY) => parse_point_column::<2>(arr), - LineString(_, XY) | LargeLineString(_, XY) => parse_line_string_column::<2>(arr), - Polygon(_, XY) | LargePolygon(_, XY) => parse_polygon_column::<2>(arr), - MultiPoint(_, XY) | LargeMultiPoint(_, XY) => parse_multi_point_column::<2>(arr), - MultiLineString(_, XY) | LargeMultiLineString(_, XY) => { - parse_multi_line_string_column::<2>(arr) - } - MultiPolygon(_, XY) | LargeMultiPolygon(_, XY) => parse_multi_polygon_column::<2>(arr), - Point(_, XYZ) => parse_point_column::<3>(arr), - LineString(_, XYZ) | LargeLineString(_, XYZ) => parse_line_string_column::<3>(arr), - Polygon(_, XYZ) | LargePolygon(_, XYZ) => parse_polygon_column::<3>(arr), - MultiPoint(_, XYZ) | LargeMultiPoint(_, XYZ) => parse_multi_point_column::<3>(arr), - MultiLineString(_, XYZ) | LargeMultiLineString(_, XYZ) => { - parse_multi_line_string_column::<3>(arr) + use NativeType::*; + + let orig_type = AnyType::try_from(orig_field)?; + let arr = array.as_ref(); + match orig_type { + AnyType::Native(t) => match t { + Point(_, XY) => parse_point_column::<2>(arr), + LineString(_, XY) | LargeLineString(_, XY) => parse_line_string_column::<2>(arr), + Polygon(_, XY) | LargePolygon(_, XY) => parse_polygon_column::<2>(arr), + MultiPoint(_, XY) | LargeMultiPoint(_, XY) => parse_multi_point_column::<2>(arr), + MultiLineString(_, XY) | LargeMultiLineString(_, XY) => { + parse_multi_line_string_column::<2>(arr) + } + MultiPolygon(_, XY) | LargeMultiPolygon(_, XY) => parse_multi_polygon_column::<2>(arr), + Point(_, XYZ) => parse_point_column::<3>(arr), + LineString(_, XYZ) | LargeLineString(_, XYZ) => parse_line_string_column::<3>(arr), + Polygon(_, XYZ) | LargePolygon(_, XYZ) => parse_polygon_column::<3>(arr), + MultiPoint(_, XYZ) | LargeMultiPoint(_, XYZ) => parse_multi_point_column::<3>(arr), + MultiLineString(_, XYZ) | LargeMultiLineString(_, XYZ) => { + parse_multi_line_string_column::<3>(arr) + } + MultiPolygon(_, XYZ) | LargeMultiPolygon(_, XYZ) => { + parse_multi_polygon_column::<3>(arr) + } + other => Err(GeoArrowError::General(format!( + "Unexpected geometry encoding: {:?}", + other + ))), + }, + AnyType::Serialized(t) => { + use SerializedType::*; + let target_geo_data_type: NativeType = target_field.try_into()?; + match t { + WKB | LargeWKB => parse_wkb_column(arr, target_geo_data_type), + } } - MultiPolygon(_, XYZ) | LargeMultiPolygon(_, XYZ) => parse_multi_polygon_column::<3>(arr), - other => Err(GeoArrowError::General(format!( - "Unexpected geometry encoding: {:?}", - other - ))), } } -fn parse_wkb_column(arr: &dyn Array, target_geo_data_type: GeoDataType) -> Result> { +fn parse_wkb_column(arr: &dyn Array, target_geo_data_type: NativeType) -> Result> { match arr.data_type() { DataType::Binary => { let wkb_arr = WKBArray::::try_from(arr)?; diff --git a/src/io/parquet/reader/spatial_filter.rs b/src/io/parquet/reader/spatial_filter.rs index 733a04f92..6aa1d830d 100644 --- a/src/io/parquet/reader/spatial_filter.rs +++ b/src/io/parquet/reader/spatial_filter.rs @@ -21,7 +21,7 @@ use crate::array::{from_arrow_array, RectArray, RectBuilder}; use crate::error::{GeoArrowError, Result}; use crate::geo_traits::{CoordTrait, RectTrait}; use crate::io::parquet::metadata::GeoParquetBboxCovering; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; /// A helper for interpreting bounding box row group statistics from GeoParquet files /// diff --git a/src/io/parquet/writer/encode.rs b/src/io/parquet/writer/encode.rs index 04c8cb7f4..2404679a6 100644 --- a/src/io/parquet/writer/encode.rs +++ b/src/io/parquet/writer/encode.rs @@ -10,7 +10,7 @@ use crate::error::Result; use crate::io::parquet::metadata::GeoParquetColumnEncoding; use crate::io::parquet::writer::metadata::{ColumnInfo, GeoParquetMetadataBuilder}; use crate::io::wkb::ToWKB; -use crate::NativeArray; +use crate::{ArrayBase, NativeArray}; pub(super) fn encode_record_batch( batch: &RecordBatch, diff --git a/src/io/parquet/writer/metadata.rs b/src/io/parquet/writer/metadata.rs index fbce6e73e..7e8f40b44 100644 --- a/src/io/parquet/writer/metadata.rs +++ b/src/io/parquet/writer/metadata.rs @@ -8,7 +8,7 @@ use serde_json::Value; use crate::algorithm::native::bounding_rect::BoundingRect; use crate::array::metadata::{ArrayMetadata, Edges}; use crate::array::{from_arrow_array, AsNativeArray, CoordType}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType, SerializedType}; use crate::error::Result; use crate::io::parquet::metadata::{ GeoParquetColumnEncoding, GeoParquetColumnMetadata, GeoParquetGeometryType, GeoParquetMetadata, @@ -41,7 +41,7 @@ impl ColumnInfo { pub fn try_new( name: String, writer_encoding: GeoParquetWriterEncoding, - data_type: &GeoDataType, + data_type: &NativeType, array_meta: ArrayMetadata, ) -> Result { let encoding = GeoParquetColumnEncoding::try_new(writer_encoding, data_type)?; @@ -80,7 +80,7 @@ impl ColumnInfo { // We only have to do this for mixed arrays because other arrays are statically known match array_ref.data_type() { - GeoDataType::Mixed(_, Dimension::XY) => { + NativeType::Mixed(_, Dimension::XY) => { let mixed_arr = array_ref.as_mixed::<2>(); if mixed_arr.has_points() { self.geometry_types.insert(GeoParquetGeometryType::Point); @@ -105,7 +105,7 @@ impl ColumnInfo { .insert(GeoParquetGeometryType::MultiPolygon); } } - GeoDataType::Mixed(_, Dimension::XYZ) => { + NativeType::Mixed(_, Dimension::XYZ) => { let mixed_arr = array_ref.as_mixed::<3>(); if mixed_arr.has_points() { self.geometry_types.insert(GeoParquetGeometryType::Point); @@ -243,71 +243,70 @@ impl GeoParquetMetadataBuilder { } } -pub fn get_geometry_types(data_type: &GeoDataType) -> HashSet { +pub fn get_geometry_types(data_type: &NativeType) -> HashSet { use GeoParquetGeometryType::*; let mut geometry_types = HashSet::new(); match data_type { - GeoDataType::Point(_, Dimension::XY) => { + NativeType::Point(_, Dimension::XY) => { geometry_types.insert(Point); } - GeoDataType::Point(_, Dimension::XYZ) => { + NativeType::Point(_, Dimension::XYZ) => { geometry_types.insert(PointZ); } - GeoDataType::LineString(_, Dimension::XY) - | GeoDataType::LargeLineString(_, Dimension::XY) => { + NativeType::LineString(_, Dimension::XY) + | NativeType::LargeLineString(_, Dimension::XY) => { geometry_types.insert(LineString); } - GeoDataType::LineString(_, Dimension::XYZ) - | GeoDataType::LargeLineString(_, Dimension::XYZ) => { + NativeType::LineString(_, Dimension::XYZ) + | NativeType::LargeLineString(_, Dimension::XYZ) => { geometry_types.insert(LineStringZ); } - GeoDataType::Polygon(_, Dimension::XY) - | GeoDataType::LargePolygon(_, Dimension::XY) - | GeoDataType::Rect(Dimension::XY) => { + NativeType::Polygon(_, Dimension::XY) + | NativeType::LargePolygon(_, Dimension::XY) + | NativeType::Rect(Dimension::XY) => { geometry_types.insert(Polygon); } - GeoDataType::Polygon(_, Dimension::XYZ) - | GeoDataType::LargePolygon(_, Dimension::XYZ) - | GeoDataType::Rect(Dimension::XYZ) => { + NativeType::Polygon(_, Dimension::XYZ) + | NativeType::LargePolygon(_, Dimension::XYZ) + | NativeType::Rect(Dimension::XYZ) => { geometry_types.insert(PolygonZ); } - GeoDataType::MultiPoint(_, Dimension::XY) - | GeoDataType::LargeMultiPoint(_, Dimension::XY) => { + NativeType::MultiPoint(_, Dimension::XY) + | NativeType::LargeMultiPoint(_, Dimension::XY) => { geometry_types.insert(MultiPoint); } - GeoDataType::MultiPoint(_, Dimension::XYZ) - | GeoDataType::LargeMultiPoint(_, Dimension::XYZ) => { + NativeType::MultiPoint(_, Dimension::XYZ) + | NativeType::LargeMultiPoint(_, Dimension::XYZ) => { geometry_types.insert(MultiPointZ); } - GeoDataType::MultiLineString(_, Dimension::XY) - | GeoDataType::LargeMultiLineString(_, Dimension::XY) => { + NativeType::MultiLineString(_, Dimension::XY) + | NativeType::LargeMultiLineString(_, Dimension::XY) => { geometry_types.insert(MultiLineString); } - GeoDataType::MultiLineString(_, Dimension::XYZ) - | GeoDataType::LargeMultiLineString(_, Dimension::XYZ) => { + NativeType::MultiLineString(_, Dimension::XYZ) + | NativeType::LargeMultiLineString(_, Dimension::XYZ) => { geometry_types.insert(MultiLineStringZ); } - GeoDataType::MultiPolygon(_, Dimension::XY) - | GeoDataType::LargeMultiPolygon(_, Dimension::XY) => { + NativeType::MultiPolygon(_, Dimension::XY) + | NativeType::LargeMultiPolygon(_, Dimension::XY) => { geometry_types.insert(MultiPolygon); } - GeoDataType::MultiPolygon(_, Dimension::XYZ) - | GeoDataType::LargeMultiPolygon(_, Dimension::XYZ) => { + NativeType::MultiPolygon(_, Dimension::XYZ) + | NativeType::LargeMultiPolygon(_, Dimension::XYZ) => { geometry_types.insert(MultiPolygonZ); } - GeoDataType::Mixed(_, _) | GeoDataType::LargeMixed(_, _) => { + NativeType::Mixed(_, _) | NativeType::LargeMixed(_, _) => { // We don't have access to the actual data here, so we can't inspect better than this. } - GeoDataType::GeometryCollection(_, Dimension::XY) - | GeoDataType::LargeGeometryCollection(_, Dimension::XY) => { + NativeType::GeometryCollection(_, Dimension::XY) + | NativeType::LargeGeometryCollection(_, Dimension::XY) => { geometry_types.insert(GeometryCollection); } - GeoDataType::GeometryCollection(_, Dimension::XYZ) - | GeoDataType::LargeGeometryCollection(_, Dimension::XYZ) => { + NativeType::GeometryCollection(_, Dimension::XYZ) + | NativeType::LargeGeometryCollection(_, Dimension::XYZ) => { geometry_types.insert(GeometryCollectionZ); } - GeoDataType::WKB | GeoDataType::LargeWKB => {} }; geometry_types @@ -340,54 +339,52 @@ fn create_output_field(column_info: &ColumnInfo, name: String, nullable: bool) - use GeoParquetGeometryType::*; match column_info.encoding { - Encoding::WKB => GeoDataType::WKB.to_field(name, nullable), + Encoding::WKB => SerializedType::WKB.to_field(name, nullable), Encoding::Point => { if column_info.geometry_types.contains(&PointZ) { - GeoDataType::Point(CoordType::Separated, Dimension::XYZ).to_field(name, nullable) + NativeType::Point(CoordType::Separated, Dimension::XYZ).to_field(name, nullable) } else { - GeoDataType::Point(CoordType::Separated, Dimension::XY).to_field(name, nullable) + NativeType::Point(CoordType::Separated, Dimension::XY).to_field(name, nullable) } } Encoding::LineString => { if column_info.geometry_types.contains(&LineStringZ) { - GeoDataType::LineString(CoordType::Separated, Dimension::XYZ) + NativeType::LineString(CoordType::Separated, Dimension::XYZ) .to_field(name, nullable) } else { - GeoDataType::LineString(CoordType::Separated, Dimension::XY) - .to_field(name, nullable) + NativeType::LineString(CoordType::Separated, Dimension::XY).to_field(name, nullable) } } Encoding::Polygon => { if column_info.geometry_types.contains(&PolygonZ) { - GeoDataType::Polygon(CoordType::Separated, Dimension::XYZ).to_field(name, nullable) + NativeType::Polygon(CoordType::Separated, Dimension::XYZ).to_field(name, nullable) } else { - GeoDataType::Polygon(CoordType::Separated, Dimension::XY).to_field(name, nullable) + NativeType::Polygon(CoordType::Separated, Dimension::XY).to_field(name, nullable) } } Encoding::MultiPoint => { if column_info.geometry_types.contains(&MultiPointZ) { - GeoDataType::MultiPoint(CoordType::Separated, Dimension::XYZ) + NativeType::MultiPoint(CoordType::Separated, Dimension::XYZ) .to_field(name, nullable) } else { - GeoDataType::MultiPoint(CoordType::Separated, Dimension::XY) - .to_field(name, nullable) + NativeType::MultiPoint(CoordType::Separated, Dimension::XY).to_field(name, nullable) } } Encoding::MultiLineString => { if column_info.geometry_types.contains(&MultiLineStringZ) { - GeoDataType::MultiLineString(CoordType::Separated, Dimension::XYZ) + NativeType::MultiLineString(CoordType::Separated, Dimension::XYZ) .to_field(name, nullable) } else { - GeoDataType::MultiLineString(CoordType::Separated, Dimension::XY) + NativeType::MultiLineString(CoordType::Separated, Dimension::XY) .to_field(name, nullable) } } Encoding::MultiPolygon => { if column_info.geometry_types.contains(&MultiPolygonZ) { - GeoDataType::MultiPolygon(CoordType::Separated, Dimension::XYZ) + NativeType::MultiPolygon(CoordType::Separated, Dimension::XYZ) .to_field(name, nullable) } else { - GeoDataType::MultiPolygon(CoordType::Separated, Dimension::XY) + NativeType::MultiPolygon(CoordType::Separated, Dimension::XY) .to_field(name, nullable) } } diff --git a/src/io/wkb/api.rs b/src/io/wkb/api.rs index 61a7272c3..a368b3200 100644 --- a/src/io/wkb/api.rs +++ b/src/io/wkb/api.rs @@ -4,10 +4,10 @@ use crate::algorithm::native::Downcast; use crate::array::geometrycollection::GeometryCollectionBuilder; use crate::array::*; use crate::chunked_array::*; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::WKB; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::NativeArray; use arrow_array::OffsetSizeTrait; @@ -153,10 +153,10 @@ impl FromWKB for Arc { /// Does not downcast automatically pub fn from_wkb( arr: &WKBArray, - target_geo_data_type: GeoDataType, + target_geo_data_type: NativeType, prefer_multi: bool, ) -> Result> { - use GeoDataType::*; + use NativeType::*; let wkb_objects: Vec>> = arr.iter().collect(); match target_geo_data_type { @@ -390,7 +390,7 @@ pub fn from_wkb( )?; Ok(Arc::new(builder.finish())) } - WKB | LargeWKB | Rect(_) => Err(GeoArrowError::General(format!( + Rect(_) => Err(GeoArrowError::General(format!( "Unexpected data type {:?}", target_geo_data_type, ))), @@ -412,7 +412,7 @@ impl ToWKB for &dyn NativeArray { type Output = WKBArray; fn to_wkb(&self) -> Self::Output { - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, Dimension::XY) => self.as_point::<2>().into(), @@ -452,8 +452,7 @@ impl ToWKB for &dyn NativeArray { LargeGeometryCollection(_, Dimension::XYZ) => { self.as_large_geometry_collection::<3>().into() } - - WKB | LargeWKB | Rect(_) => todo!(), + Rect(_) => todo!(), } } } @@ -462,7 +461,7 @@ impl ToWKB for &dyn ChunkedNativeArray { type Output = ChunkedWKBArray; fn to_wkb(&self) -> Self::Output { - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, Dimension::XY) => { @@ -559,14 +558,14 @@ impl ToWKB for &dyn ChunkedNativeArray { self.as_large_geometry_collection::<3>() .map(|chunk| chunk.into()), ), - WKB | LargeWKB | Rect(_) => todo!(), + Rect(_) => todo!(), } } } /// Convert a geometry array to a [WKBArray]. pub fn to_wkb(arr: &dyn NativeArray) -> WKBArray { - use GeoDataType::*; + use NativeType::*; match arr.data_type() { Point(_, Dimension::XY) => arr.as_point::<2>().into(), @@ -601,7 +600,7 @@ pub fn to_wkb(arr: &dyn NativeArray) -> WKBArray { LargeGeometryCollection(_, Dimension::XYZ) => { arr.as_large_geometry_collection::<3>().into() } - WKB | LargeWKB | Rect(_) => todo!(), + Rect(_) => todo!(), } } @@ -616,7 +615,7 @@ mod test { let wkb_arr: WKBArray = to_wkb(&arr); let roundtrip = from_wkb( &wkb_arr, - GeoDataType::Point(CoordType::Interleaved, Dimension::XY), + NativeType::Point(CoordType::Interleaved, Dimension::XY), true, ) .unwrap(); @@ -631,7 +630,7 @@ mod test { let wkb_arr: WKBArray = to_wkb(&arr); let roundtrip = from_wkb( &wkb_arr, - GeoDataType::Mixed(CoordType::Interleaved, Dimension::XY), + NativeType::Mixed(CoordType::Interleaved, Dimension::XY), true, ) .unwrap(); @@ -649,7 +648,7 @@ mod test { let wkb_arr: WKBArray = to_wkb(&arr); let roundtrip_mixed = from_wkb( &wkb_arr, - GeoDataType::Mixed(CoordType::Interleaved, Dimension::XYZ), + NativeType::Mixed(CoordType::Interleaved, Dimension::XYZ), false, ) .unwrap(); @@ -659,7 +658,7 @@ mod test { let roundtrip_point = from_wkb( &wkb_arr, - GeoDataType::Point(CoordType::Interleaved, Dimension::XYZ), + NativeType::Point(CoordType::Interleaved, Dimension::XYZ), false, ) .unwrap(); diff --git a/src/io/wkb/reader/type.rs b/src/io/wkb/reader/type.rs index 584531fe2..19627322a 100644 --- a/src/io/wkb/reader/type.rs +++ b/src/io/wkb/reader/type.rs @@ -5,7 +5,7 @@ use arrow_array::OffsetSizeTrait; use num_enum::TryFromPrimitive; use crate::array::CoordType; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::io::wkb::common::WKBType; use crate::scalar::WKB; @@ -112,7 +112,7 @@ impl AvailableTypes { self.mixed = false; } - pub fn resolve_type(self, large_type: bool, coord_type: CoordType) -> Result { + pub fn resolve_type(self, large_type: bool, coord_type: CoordType) -> Result { if self.all_true() { return Err(GeoArrowError::General( "No geometries have been added.".to_string(), @@ -120,58 +120,58 @@ impl AvailableTypes { } let t = if self.point { - GeoDataType::Point(coord_type, Dimension::XY) + NativeType::Point(coord_type, Dimension::XY) } else if self.line_string { if large_type { - GeoDataType::LargeLineString(coord_type, Dimension::XY) + NativeType::LargeLineString(coord_type, Dimension::XY) } else { - GeoDataType::LineString(coord_type, Dimension::XY) + NativeType::LineString(coord_type, Dimension::XY) } } else if self.polygon { if large_type { - GeoDataType::LargePolygon(coord_type, Dimension::XY) + NativeType::LargePolygon(coord_type, Dimension::XY) } else { - GeoDataType::Polygon(coord_type, Dimension::XY) + NativeType::Polygon(coord_type, Dimension::XY) } } else if self.multi_point { if large_type { - GeoDataType::LargeMultiPoint(coord_type, Dimension::XY) + NativeType::LargeMultiPoint(coord_type, Dimension::XY) } else { - GeoDataType::MultiPoint(coord_type, Dimension::XY) + NativeType::MultiPoint(coord_type, Dimension::XY) } } else if self.multi_line_string { if large_type { - GeoDataType::LargeMultiLineString(coord_type, Dimension::XY) + NativeType::LargeMultiLineString(coord_type, Dimension::XY) } else { - GeoDataType::MultiLineString(coord_type, Dimension::XY) + NativeType::MultiLineString(coord_type, Dimension::XY) } } else if self.multi_polygon { if large_type { - GeoDataType::LargeMultiPolygon(coord_type, Dimension::XY) + NativeType::LargeMultiPolygon(coord_type, Dimension::XY) } else { - GeoDataType::MultiPolygon(coord_type, Dimension::XY) + NativeType::MultiPolygon(coord_type, Dimension::XY) } } else if self.mixed { if large_type { - GeoDataType::LargeMixed(coord_type, Dimension::XY) + NativeType::LargeMixed(coord_type, Dimension::XY) } else { - GeoDataType::Mixed(coord_type, Dimension::XY) + NativeType::Mixed(coord_type, Dimension::XY) } } else if large_type { - GeoDataType::LargeGeometryCollection(coord_type, Dimension::XY) + NativeType::LargeGeometryCollection(coord_type, Dimension::XY) } else { - GeoDataType::GeometryCollection(coord_type, Dimension::XY) + NativeType::GeometryCollection(coord_type, Dimension::XY) }; Ok(t) } } -/// Infer the minimal GeoDataType that a sequence of WKB geometries can be casted to. +/// Infer the minimal NativeType that a sequence of WKB geometries can be casted to. pub(crate) fn infer_geometry_type<'a, O: OffsetSizeTrait>( geoms: impl Iterator>, large_type: bool, coord_type: CoordType, -) -> Result { +) -> Result { let mut available_type = AvailableTypes::new(); for geom in geoms { match geom.get_wkb_geometry_type() { diff --git a/src/io/wkb/writer/geometry.rs b/src/io/wkb/writer/geometry.rs index d3f75960a..c9303edae 100644 --- a/src/io/wkb/writer/geometry.rs +++ b/src/io/wkb/writer/geometry.rs @@ -10,8 +10,8 @@ use crate::io::wkb::writer::{ write_line_string_as_wkb, write_multi_line_string_as_wkb, write_multi_point_as_wkb, write_multi_polygon_as_wkb, write_point_as_wkb, write_polygon_as_wkb, }; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use std::io::{Cursor, Write}; /// The byte length of a Geometry diff --git a/src/io/wkb/writer/geometrycollection.rs b/src/io/wkb/writer/geometrycollection.rs index aaccc9abb..c98be0a63 100644 --- a/src/io/wkb/writer/geometrycollection.rs +++ b/src/io/wkb/writer/geometrycollection.rs @@ -5,8 +5,8 @@ use crate::geo_traits::GeometryCollectionTrait; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; use crate::io::wkb::writer::geometry::{geometry_wkb_size, write_geometry_as_wkb}; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/linestring.rs b/src/io/wkb/writer/linestring.rs index f30ec9624..cb84809e1 100644 --- a/src/io/wkb/writer/linestring.rs +++ b/src/io/wkb/writer/linestring.rs @@ -4,8 +4,8 @@ use crate::error::Result; use crate::geo_traits::{CoordTrait, LineStringTrait}; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/multilinestring.rs b/src/io/wkb/writer/multilinestring.rs index 80ca5ddcb..73290cdf3 100644 --- a/src/io/wkb/writer/multilinestring.rs +++ b/src/io/wkb/writer/multilinestring.rs @@ -5,8 +5,8 @@ use crate::geo_traits::MultiLineStringTrait; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; use crate::io::wkb::writer::linestring::{line_string_wkb_size, write_line_string_as_wkb}; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/multipoint.rs b/src/io/wkb/writer/multipoint.rs index 532d332d1..2e1bf71a7 100644 --- a/src/io/wkb/writer/multipoint.rs +++ b/src/io/wkb/writer/multipoint.rs @@ -5,8 +5,8 @@ use crate::geo_traits::MultiPointTrait; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; use crate::io::wkb::writer::point::{point_wkb_size, write_point_as_wkb}; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/multipolygon.rs b/src/io/wkb/writer/multipolygon.rs index 600bc8e15..284474d3b 100644 --- a/src/io/wkb/writer/multipolygon.rs +++ b/src/io/wkb/writer/multipolygon.rs @@ -5,8 +5,8 @@ use crate::geo_traits::MultiPolygonTrait; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; use crate::io::wkb::writer::polygon::{polygon_wkb_size, write_polygon_as_wkb}; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/point.rs b/src/io/wkb/writer/point.rs index 330aceed2..35655f782 100644 --- a/src/io/wkb/writer/point.rs +++ b/src/io/wkb/writer/point.rs @@ -4,8 +4,8 @@ use crate::error::Result; use crate::geo_traits::PointTrait; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; diff --git a/src/io/wkb/writer/polygon.rs b/src/io/wkb/writer/polygon.rs index 566f14c2d..a419196b7 100644 --- a/src/io/wkb/writer/polygon.rs +++ b/src/io/wkb/writer/polygon.rs @@ -4,8 +4,8 @@ use crate::error::Result; use crate::geo_traits::{CoordTrait, LineStringTrait, PolygonTrait}; use crate::io::wkb::common::WKBType; use crate::io::wkb::reader::Endianness; -use crate::trait_::NativeArray; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; +use crate::ArrayBase; use arrow_array::{GenericBinaryArray, OffsetSizeTrait}; use byteorder::{LittleEndian, WriteBytesExt}; use std::io::{Cursor, Write}; @@ -126,7 +126,7 @@ impl From<&PolygonArray< mod test { use super::*; use crate::test::polygon::{p0, p1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; use geozero::{CoordDimensions, ToWkb}; #[test] diff --git a/src/lib.rs b/src/lib.rs index 05dd73efc..72abad906 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -58,7 +58,7 @@ #![cfg_attr(not(test), deny(unused_crate_dependencies))] #![deny(missing_docs)] // FIXME some modules allow missing docs -pub use trait_::NativeArray; +pub use trait_::{ArrayBase, NativeArray}; pub mod algorithm; pub mod array; diff --git a/src/scalar/geometrycollection/scalar.rs b/src/scalar/geometrycollection/scalar.rs index 87999e578..538a5730a 100644 --- a/src/scalar/geometrycollection/scalar.rs +++ b/src/scalar/geometrycollection/scalar.rs @@ -4,7 +4,7 @@ use crate::array::MixedGeometryArray; use crate::geo_traits::GeometryCollectionTrait; use crate::io::geo::geometry_collection_to_geo; use crate::scalar::Geometry; -use crate::trait_::NativeArrayAccessor; +use crate::trait_::ArrayAccessor; use crate::trait_::NativeScalar; use arrow_array::OffsetSizeTrait; use arrow_buffer::OffsetBuffer; diff --git a/src/scalar/linestring/scalar.rs b/src/scalar/linestring/scalar.rs index 795a81836..91a8480f0 100644 --- a/src/scalar/linestring/scalar.rs +++ b/src/scalar/linestring/scalar.rs @@ -141,7 +141,7 @@ impl> PartialEq for LineStrin mod test { use crate::array::LineStringArray; use crate::test::linestring::{ls0, ls1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/multilinestring/scalar.rs b/src/scalar/multilinestring/scalar.rs index a8eabe338..bdbd9634f 100644 --- a/src/scalar/multilinestring/scalar.rs +++ b/src/scalar/multilinestring/scalar.rs @@ -155,7 +155,7 @@ impl> PartialEq mod test { use crate::array::MultiLineStringArray; use crate::test::multilinestring::{ml0, ml1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/multipoint/scalar.rs b/src/scalar/multipoint/scalar.rs index 5014be33c..345ff2f26 100644 --- a/src/scalar/multipoint/scalar.rs +++ b/src/scalar/multipoint/scalar.rs @@ -144,7 +144,7 @@ impl> PartialEq< mod test { use crate::array::MultiPointArray; use crate::test::multipoint::{mp0, mp1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/multipolygon/scalar.rs b/src/scalar/multipolygon/scalar.rs index ed5e9384b..8e895da9c 100644 --- a/src/scalar/multipolygon/scalar.rs +++ b/src/scalar/multipolygon/scalar.rs @@ -174,7 +174,7 @@ impl> PartialE mod test { use crate::array::MultiPolygonArray; use crate::test::multipolygon::{mp0, mp1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/point/scalar.rs b/src/scalar/point/scalar.rs index d20200056..bd41a6b3e 100644 --- a/src/scalar/point/scalar.rs +++ b/src/scalar/point/scalar.rs @@ -157,7 +157,7 @@ impl, const D: usize> PartialEq for Point<'_, D> { #[cfg(test)] mod test { use crate::array::{CoordBuffer, PointArray}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/polygon/scalar.rs b/src/scalar/polygon/scalar.rs index e67172c04..61f729585 100644 --- a/src/scalar/polygon/scalar.rs +++ b/src/scalar/polygon/scalar.rs @@ -172,7 +172,7 @@ impl, const D: usize> PartialEq mod test { use crate::array::PolygonArray; use crate::test::polygon::{p0, p1}; - use crate::trait_::NativeArrayAccessor; + use crate::trait_::ArrayAccessor; /// Test Eq where the current index is true but another index is false #[test] diff --git a/src/scalar/scalar.rs b/src/scalar/scalar.rs index 14db4f8e5..ede8af20c 100644 --- a/src/scalar/scalar.rs +++ b/src/scalar/scalar.rs @@ -4,11 +4,10 @@ use crate::array::{ AsNativeArray, GeometryCollectionArray, LineStringArray, MixedGeometryArray, MultiLineStringArray, MultiPointArray, MultiPolygonArray, PointArray, PolygonArray, RectArray, }; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; -use crate::io::geo::geometry_to_geo; use crate::scalar::Geometry; -use crate::trait_::{NativeArrayAccessor, NativeArrayRef, NativeScalar}; +use crate::trait_::{ArrayAccessor, NativeArrayRef, NativeScalar}; /// A dynamically typed GeoArrow scalar /// @@ -30,7 +29,7 @@ impl GeometryScalar { } } - pub fn data_type(&self) -> GeoDataType { + pub fn data_type(&self) -> NativeType { self.0.data_type() } @@ -43,7 +42,7 @@ impl GeometryScalar { } pub fn dimension(&self) -> Dimension { - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, dim) | LineString(_, dim) @@ -61,23 +60,23 @@ impl GeometryScalar { | GeometryCollection(_, dim) | LargeGeometryCollection(_, dim) | Rect(dim) => dim, - WKB => { - let arr = self.0.as_ref(); - let wkb_arr = arr.as_wkb().value(0); - let wkb_obj = wkb_arr.to_wkb_object(); - wkb_obj.dimension() - } - LargeWKB => { - let arr = self.0.as_ref(); - let wkb_arr = arr.as_large_wkb().value(0); - let wkb_obj = wkb_arr.to_wkb_object(); - wkb_obj.dimension() - } + // WKB => { + // let arr = self.0.as_ref(); + // let wkb_arr = arr.as_wkb().value(0); + // let wkb_obj = wkb_arr.to_wkb_object(); + // wkb_obj.dimension() + // } + // LargeWKB => { + // let arr = self.0.as_ref(); + // let wkb_arr = arr.as_large_wkb().value(0); + // let wkb_obj = wkb_arr.to_wkb_object(); + // wkb_obj.dimension() + // } } } pub fn as_geometry(&self) -> Option> { - use GeoDataType::*; + use NativeType::*; // Note: we use `.downcast_ref` directly here because we need to pass in the generic match self.data_type() { @@ -145,9 +144,6 @@ impl GeometryScalar { let arr = self.0.as_any().downcast_ref::>().unwrap(); arr.get(0).map(Geometry::Rect) } - WKB | LargeWKB => { - panic!("WKB and LargeWKB not supported here") - } } } @@ -163,7 +159,7 @@ impl GeometryScalar { } use Dimension::*; - use GeoDataType::*; + use NativeType::*; match self.data_type() { Point(_, XY) => impl_to_geo!(as_point, 2), @@ -218,18 +214,18 @@ impl GeometryScalar { impl_to_geo!(as_large_geometry_collection, 3) } Rect(XYZ) => impl_to_geo!(as_rect, 3), - WKB => { - let arr = self.0.as_ref(); - let wkb_arr = arr.as_wkb().value(0); - let wkb_object = wkb_arr.to_wkb_object(); - geometry_to_geo(&wkb_object) - } - LargeWKB => { - let arr = self.0.as_ref(); - let wkb_arr = arr.as_large_wkb().value(0); - let wkb_object = wkb_arr.to_wkb_object(); - geometry_to_geo(&wkb_object) - } + // WKB => { + // let arr = self.0.as_ref(); + // let wkb_arr = arr.as_wkb().value(0); + // let wkb_object = wkb_arr.to_wkb_object(); + // geometry_to_geo(&wkb_object) + // } + // LargeWKB => { + // let arr = self.0.as_ref(); + // let wkb_arr = arr.as_large_wkb().value(0); + // let wkb_object = wkb_arr.to_wkb_object(); + // geometry_to_geo(&wkb_object) + // } } } @@ -390,7 +386,7 @@ impl GeometryScalar { // Self::Rect<'_>, // > { // use Dimension::*; -// use GeoDataType::*; +// use NativeType::*; // match self.data_type() { // Point(_, XY) => { diff --git a/src/table.rs b/src/table.rs index 460617afe..8e1b07f07 100644 --- a/src/table.rs +++ b/src/table.rs @@ -13,7 +13,7 @@ use crate::array::metadata::ArrayMetadata; use crate::array::*; use crate::chunked_array::ChunkedArray; use crate::chunked_array::{from_arrow_chunks, from_geoarrow_chunks, ChunkedNativeArray}; -use crate::datatypes::{Dimension, GeoDataType}; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::io::wkb::from_wkb; use crate::schema::GeoSchemaExt; @@ -150,17 +150,17 @@ impl Table { /// # #[cfg(feature = "geozero")] /// # { /// use std::fs::File; - /// use geoarrow::{array::CoordType, datatypes::{GeoDataType, Dimension}}; + /// use geoarrow::{array::CoordType, datatypes::{NativeType, Dimension}}; /// /// let file = File::open("fixtures/roads.geojson").unwrap(); /// let mut table = geoarrow::io::geojson::read_geojson(file, Default::default()).unwrap(); /// let index = table.default_geometry_column_idx().unwrap(); /// /// // Change to separated storage of coordinates - /// table.cast_geometry(index, &GeoDataType::LineString(CoordType::Separated, Dimension::XY)).unwrap(); + /// table.cast_geometry(index, &NativeType::LineString(CoordType::Separated, Dimension::XY)).unwrap(); /// # } /// ``` - pub fn cast_geometry(&mut self, index: usize, to_type: &GeoDataType) -> Result<()> { + pub fn cast_geometry(&mut self, index: usize, to_type: &NativeType) -> Result<()> { let orig_field = self.schema().field(index); let array_slices = self @@ -188,10 +188,10 @@ impl Table { pub fn parse_geometry_to_native( &mut self, index: usize, - target_geo_data_type: Option, + target_geo_data_type: Option, ) -> Result<()> { let target_geo_data_type = target_geo_data_type - .unwrap_or(GeoDataType::LargeMixed(Default::default(), Dimension::XY)); + .unwrap_or(NativeType::LargeMixed(Default::default(), Dimension::XY)); let orig_field = self.schema().field(index); let geoarray_metadata = ArrayMetadata::try_from(orig_field)?; @@ -215,7 +215,7 @@ impl Table { // Parse WKB let new_geometry = match chunked_geometry.data_type() { - GeoDataType::WKB => { + NativeType::WKB => { let parsed_chunks = chunked_geometry .as_ref() .as_wkb() @@ -231,7 +231,7 @@ impl Table { .as_ref() .downcast(true) } - GeoDataType::LargeWKB => { + NativeType::LargeWKB => { let parsed_chunks = chunked_geometry .as_ref() .as_large_wkb() @@ -270,7 +270,7 @@ impl Table { batches: Vec, schema: SchemaRef, geometry_column_index: Option, - target_geo_data_type: Option, + target_geo_data_type: Option, ) -> Result { if batches.is_empty() { return Self::try_new(batches, schema); @@ -324,9 +324,9 @@ impl Table { from_arrow_chunks(orig_geom_slices.as_slice(), original_geometry_field)?; let target_geo_data_type = target_geo_data_type - .unwrap_or(GeoDataType::LargeMixed(Default::default(), Dimension::XY)); + .unwrap_or(NativeType::LargeMixed(Default::default(), Dimension::XY)); match chunked_geometry_array.data_type() { - GeoDataType::WKB => { + NativeType::WKB => { let parsed_chunks = chunked_geometry_array .as_ref() .as_wkb() @@ -342,7 +342,7 @@ impl Table { .as_ref() .downcast(true); } - GeoDataType::LargeWKB => { + NativeType::LargeWKB => { let parsed_chunks = chunked_geometry_array .as_ref() .as_large_wkb() diff --git a/src/test/point.rs b/src/test/point.rs index 0df79a73c..8f48ae8a6 100644 --- a/src/test/point.rs +++ b/src/test/point.rs @@ -9,7 +9,7 @@ use crate::array::PointArray; use crate::geo_traits::PointTrait; use crate::table::Table; use crate::test::properties; -use crate::NativeArray; +use crate::ArrayBase; pub(crate) fn p0() -> Point { point!( diff --git a/src/trait_.rs b/src/trait_.rs index 3b7517e8e..69e914951 100644 --- a/src/trait_.rs +++ b/src/trait_.rs @@ -2,21 +2,15 @@ use crate::array::metadata::ArrayMetadata; use crate::array::{CoordBuffer, CoordType}; -use crate::datatypes::GeoDataType; +use crate::datatypes::NativeType; use arrow_array::{Array, ArrayRef}; use arrow_buffer::{NullBuffer, NullBufferBuilder}; use arrow_schema::{DataType, Field}; use std::any::Any; use std::sync::Arc; -/// A trait to represent native-encoded GeoArrow arrays -/// -/// This encompasses the core GeoArrow [native encoding](https://github.com/geoarrow/geoarrow/blob/main/format.md#native-encoding) types. -/// -/// This trait is often used for downcasting. If you have a dynamically-typed `Arc`, to downcast into a strongly-typed chunked array use `as_any` with the -/// `data_type` method to discern which chunked array type to pass to `downcast_ref`. -pub trait NativeArray: std::fmt::Debug + Send + Sync { +/// A base trait that both [NativeArray] and [SerializedArray] implement +pub trait ArrayBase: std::fmt::Debug + Send + Sync { /// Returns the array as [`Any`] so that it can be /// downcasted to a specific implementation. /// @@ -41,25 +35,12 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { /// ``` fn as_any(&self) -> &dyn Any; - /// Returns a the [`GeoDataType`] of this array. - /// - /// # Examples - /// - /// ``` - /// use geoarrow::{array::PointArray, datatypes::GeoDataType, NativeArray}; - /// - /// let point = geo::point!(x: 1., y: 2.); - /// let point_array: PointArray<2> = vec![point].as_slice().into(); - /// assert!(matches!(point_array.data_type(), GeoDataType::Point(_, _))); - /// ``` - fn data_type(&self) -> GeoDataType; - /// Returns the physical [DataType] of this array. /// /// # Examples /// /// ``` - /// use geoarrow::{array::PointArray, datatypes::GeoDataType, NativeArray}; + /// use geoarrow::{array::PointArray, datatypes::NativeType, NativeArray}; /// use arrow_schema::DataType; /// /// let point = geo::point!(x: 1., y: 2.); @@ -130,33 +111,6 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { #[must_use] fn to_array_ref(&self) -> ArrayRef; - /// Returns the [CoordType] of this geometry array. - /// - /// # Examples - /// - /// ``` - /// use geoarrow::{array::{PointArray, CoordType}, NativeArray}; - /// - /// let point = geo::point!(x: 1., y: 2.); - /// let point_array: PointArray<2> = vec![point].as_slice().into(); - /// assert_eq!(point_array.coord_type(), CoordType::Interleaved); - /// ``` - fn coord_type(&self) -> CoordType; - - /// Converts this array to the same type of array but with the provided [CoordType]. - /// - /// # Examples - /// - /// ``` - /// use geoarrow::{array::{PointArray, CoordType}, NativeArray}; - /// - /// let point = geo::point!(x: 1., y: 2.); - /// let point_array: PointArray<2> = vec![point].as_slice().into(); - /// let point_array = point_array.to_coord_type(CoordType::Separated); - /// ``` - #[must_use] - fn to_coord_type(&self, coord_type: CoordType) -> Arc; - /// The number of geometries contained in this array. /// /// # Examples @@ -215,24 +169,6 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { /// ``` fn metadata(&self) -> Arc; - /// Returns a geometry array reference that includes the provided metadata. - /// - /// # Examples - /// - /// ``` - /// use geoarrow::{NativeArray, array::{PointArray, metadata::{ArrayMetadata, Edges}}}; - /// - /// let point = geo::point!(x: 1., y: 2.); - /// let array: PointArray<2> = vec![point].as_slice().into(); - /// let metadata = ArrayMetadata { - /// crs: None, - /// edges: Some(Edges::Spherical), - /// }; - /// let metadata = array.with_metadata(metadata.into()); - /// ``` - #[must_use] - fn with_metadata(&self, metadata: Arc) -> NativeArrayRef; - /// Returns the number of null slots in this array. /// /// This is `O(1)` since the number of null elements is pre-computed. @@ -290,6 +226,73 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { fn is_valid(&self, i: usize) -> bool { !self.is_null(i) } +} + +/// A trait to represent native-encoded GeoArrow arrays +/// +/// This encompasses the core GeoArrow [native encoding](https://github.com/geoarrow/geoarrow/blob/main/format.md#native-encoding) types. +/// +/// This trait is often used for downcasting. If you have a dynamically-typed `Arc`, to downcast into a strongly-typed chunked array use `as_any` with the +/// `data_type` method to discern which chunked array type to pass to `downcast_ref`. +pub trait NativeArray: ArrayBase { + /// Returns a the [`NativeType`] of this array. + /// + /// # Examples + /// + /// ``` + /// use geoarrow::{array::PointArray, datatypes::NativeType, NativeArray}; + /// + /// let point = geo::point!(x: 1., y: 2.); + /// let point_array: PointArray<2> = vec![point].as_slice().into(); + /// assert!(matches!(point_array.data_type(), NativeType::Point(_, _))); + /// ``` + fn data_type(&self) -> NativeType; + + /// Returns the [CoordType] of this geometry array. + /// + /// # Examples + /// + /// ``` + /// use geoarrow::{array::{PointArray, CoordType}, NativeArray}; + /// + /// let point = geo::point!(x: 1., y: 2.); + /// let point_array: PointArray<2> = vec![point].as_slice().into(); + /// assert_eq!(point_array.coord_type(), CoordType::Interleaved); + /// ``` + fn coord_type(&self) -> CoordType; + + /// Converts this array to the same type of array but with the provided [CoordType]. + /// + /// # Examples + /// + /// ``` + /// use geoarrow::{array::{PointArray, CoordType}, NativeArray}; + /// + /// let point = geo::point!(x: 1., y: 2.); + /// let point_array: PointArray<2> = vec![point].as_slice().into(); + /// let point_array = point_array.to_coord_type(CoordType::Separated); + /// ``` + #[must_use] + fn to_coord_type(&self, coord_type: CoordType) -> Arc; + + /// Returns a geometry array reference that includes the provided metadata. + /// + /// # Examples + /// + /// ``` + /// use geoarrow::{NativeArray, array::{PointArray, metadata::{ArrayMetadata, Edges}}}; + /// + /// let point = geo::point!(x: 1., y: 2.); + /// let array: PointArray<2> = vec![point].as_slice().into(); + /// let metadata = ArrayMetadata { + /// crs: None, + /// edges: Some(Edges::Spherical), + /// }; + /// let metadata = array.with_metadata(metadata.into()); + /// ``` + #[must_use] + fn with_metadata(&self, metadata: Arc) -> NativeArrayRef; /// Returns a reference to this array. /// @@ -311,7 +314,7 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { /// ``` /// use geoarrow::{ /// array::PointArray, - /// trait_::{GeometryArraySelfMethods, NativeArrayAccessor, NativeArray} + /// trait_::{GeometryArraySelfMethods, ArrayAccessor, NativeArray} /// }; /// /// let point_0 = geo::point!(x: 1., y: 2.); @@ -344,11 +347,6 @@ pub trait NativeArray: std::fmt::Debug + Send + Sync { /// ``` #[must_use] fn owned_slice(&self, offset: usize, length: usize) -> Arc; - - // /// Clones this [`GeometryArray`] with a new new assigned bitmap. - // /// # Panic - // /// This function panics iff `validity.len() != self.len()`. - // fn with_validity(&self, validity: Option) -> Box; } /// Type alias for a dynamic reference to something that implements [NativeArray]. @@ -358,12 +356,12 @@ pub type NativeArrayRef = Arc; /// /// # Validity /// -/// An [`NativeArrayAccessor`] must always return a well-defined value for an index that is +/// An [`ArrayAccessor`] must always return a well-defined value for an index that is /// within the bounds `0..Array::len`, including for null indexes where [`Array::is_null`] is true. /// /// The value at null indexes is unspecified, and implementations must not rely on a specific /// value such as [`Default::default`] being returned, however, it must not be undefined. -pub trait NativeArrayAccessor<'a>: NativeArray { +pub trait ArrayAccessor<'a>: ArrayBase { /// The [geoarrow scalar object][crate::scalar] for this geometry array type. type Item: Send + Sync + NativeScalar; @@ -375,7 +373,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray, geo_traits::PointTrait}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray, geo_traits::PointTrait}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -397,7 +395,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -416,7 +414,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -435,7 +433,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -460,7 +458,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -477,7 +475,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -496,7 +494,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -511,7 +509,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -526,7 +524,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -541,7 +539,7 @@ pub trait NativeArrayAccessor<'a>: NativeArray { /// # Examples /// /// ``` - /// use geoarrow::{trait_::NativeArrayAccessor, array::PointArray}; + /// use geoarrow::{trait_::ArrayAccessor, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -566,7 +564,7 @@ pub trait GeometryArraySelfMethods { /// ``` /// use geoarrow::{ /// array::{PointArray, CoordBuffer, InterleavedCoordBuffer}, - /// trait_::{GeometryArraySelfMethods, NativeArrayAccessor}, + /// trait_::{GeometryArraySelfMethods, ArrayAccessor}, /// }; /// /// let point = geo::point!(x: 1., y: 2.); @@ -586,7 +584,7 @@ pub trait GeometryArraySelfMethods { /// ``` /// use geoarrow::{ /// array::{PointArray, CoordType, CoordBuffer}, - /// trait_::{NativeArrayAccessor, GeometryArraySelfMethods}, + /// trait_::{ArrayAccessor, GeometryArraySelfMethods}, /// }; /// /// let point_0 = geo::point!(x: 1., y: 2.); @@ -627,7 +625,7 @@ pub trait NativeScalar { /// # Examples /// /// ``` - /// use geoarrow::{trait_::{NativeScalar, NativeArrayAccessor}, array::PointArray}; + /// use geoarrow::{trait_::{NativeScalar, ArrayAccessor}, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -642,7 +640,7 @@ pub trait NativeScalar { /// # Examples /// /// ``` - /// use geoarrow::{trait_::{NativeScalar, NativeArrayAccessor}, array::PointArray}; + /// use geoarrow::{trait_::{NativeScalar, ArrayAccessor}, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into(); @@ -655,7 +653,7 @@ pub trait NativeScalar { /// # Examples /// /// ``` - /// use geoarrow::{trait_::{NativeScalar, NativeArrayAccessor}, array::PointArray}; + /// use geoarrow::{trait_::{NativeScalar, ArrayAccessor}, array::PointArray}; /// /// let point = geo::point!(x: 1., y: 2.); /// let array: PointArray<2> = vec![point].as_slice().into();