diff --git a/rust/geoarrow/src/algorithm/geo/euclidean_distance.rs b/rust/geoarrow/src/algorithm/geo/euclidean_distance.rs index 81910129..054c48a6 100644 --- a/rust/geoarrow/src/algorithm/geo/euclidean_distance.rs +++ b/rust/geoarrow/src/algorithm/geo/euclidean_distance.rs @@ -57,7 +57,7 @@ pub trait EuclideanDistance { /// /// let distance = point.euclidean_distance(&polygon); /// - /// assert_relative_eq!(distance, 2.1213203435596424); + /// assert_relative_eq!(distance.1213203435596424); /// ``` /// /// `Point` to `LineString`: @@ -186,9 +186,9 @@ iter_geo_impl!(MultiPolygonArray, PointArray); // └─────────────────────────────────┘ // Note: this implementation is outside the macro because it is not generic over O -impl<'a> EuclideanDistance> for PointArray { +impl<'a> EuclideanDistance> for PointArray { /// Minimum distance between two Points - fn euclidean_distance(&self, other: &Point<'a, 2>) -> Float64Array { + fn euclidean_distance(&self, other: &Point<'a>) -> Float64Array { let mut output_array = Float64Builder::with_capacity(self.len()); self.iter_geo().for_each(|maybe_point| { @@ -220,48 +220,48 @@ macro_rules! iter_geo_impl_scalar { } // Implementations on PointArray -iter_geo_impl_scalar!(PointArray, LineString<'a, 2>); -iter_geo_impl_scalar!(PointArray, Polygon<'a, 2>); -iter_geo_impl_scalar!(PointArray, MultiPoint<'a, 2>); -iter_geo_impl_scalar!(PointArray, MultiLineString<'a, 2>); -iter_geo_impl_scalar!(PointArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(PointArray, LineString<'a>); +iter_geo_impl_scalar!(PointArray, Polygon<'a>); +iter_geo_impl_scalar!(PointArray, MultiPoint<'a>); +iter_geo_impl_scalar!(PointArray, MultiLineString<'a>); +iter_geo_impl_scalar!(PointArray, MultiPolygon<'a>); // Implementations on LineStringArray -iter_geo_impl_scalar!(LineStringArray, Point<'a, 2>); -iter_geo_impl_scalar!(LineStringArray, LineString<'a, 2>); -iter_geo_impl_scalar!(LineStringArray, Polygon<'a, 2>); -// iter_geo_impl_scalar!(LineStringArray, MultiPoint<'a, 2>); -// iter_geo_impl_scalar!(LineStringArray, MultiLineString<'a, 2>); -// iter_geo_impl_scalar!(LineStringArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(LineStringArray, Point<'a>); +iter_geo_impl_scalar!(LineStringArray, LineString<'a>); +iter_geo_impl_scalar!(LineStringArray, Polygon<'a>); +// iter_geo_impl_scalar!(LineStringArray, MultiPoint<'a>); +// iter_geo_impl_scalar!(LineStringArray, MultiLineString<'a>); +// iter_geo_impl_scalar!(LineStringArray, MultiPolygon<'a>); // Implementations on PolygonArray -iter_geo_impl_scalar!(PolygonArray, Point<'a, 2>); -iter_geo_impl_scalar!(PolygonArray, LineString<'a, 2>); -iter_geo_impl_scalar!(PolygonArray, Polygon<'a, 2>); -// iter_geo_impl_scalar!(PolygonArray, MultiPoint<'a, 2>); -// iter_geo_impl_scalar!(PolygonArray, MultiLineString<'a, 2>); -// iter_geo_impl_scalar!(PolygonArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(PolygonArray, Point<'a>); +iter_geo_impl_scalar!(PolygonArray, LineString<'a>); +iter_geo_impl_scalar!(PolygonArray, Polygon<'a>); +// iter_geo_impl_scalar!(PolygonArray, MultiPoint<'a>); +// iter_geo_impl_scalar!(PolygonArray, MultiLineString<'a>); +// iter_geo_impl_scalar!(PolygonArray, MultiPolygon<'a>); // Implementations on MultiPointArray -iter_geo_impl_scalar!(MultiPointArray, Point<'a, 2>); -// iter_geo_impl_scalar!(MultiPointArray, LineString<'a, 2>); -// iter_geo_impl_scalar!(MultiPointArray, Polygon<'a, 2>); -// iter_geo_impl_scalar!(MultiPointArray, MultiPoint<'a, 2>); -// iter_geo_impl_scalar!(MultiPointArray, MultiLineString<'a, 2>); -// iter_geo_impl_scalar!(MultiPointArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(MultiPointArray, Point<'a>); +// iter_geo_impl_scalar!(MultiPointArray, LineString<'a>); +// iter_geo_impl_scalar!(MultiPointArray, Polygon<'a>); +// iter_geo_impl_scalar!(MultiPointArray, MultiPoint<'a>); +// iter_geo_impl_scalar!(MultiPointArray, MultiLineString<'a>); +// iter_geo_impl_scalar!(MultiPointArray, MultiPolygon<'a>); // Implementations on MultiLineStringArray -iter_geo_impl_scalar!(MultiLineStringArray, Point<'a, 2>); -// iter_geo_impl_scalar!(MultiLineStringArray, LineString<'a, 2>); -// iter_geo_impl_scalar!(MultiLineStringArray, Polygon<'a, 2>); -// iter_geo_impl_scalar!(MultiLineStringArray, MultiPoint<'a, 2>); -// iter_geo_impl_scalar!(MultiLineStringArray, MultiLineString<'a, 2>); -// iter_geo_impl_scalar!(MultiLineStringArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(MultiLineStringArray, Point<'a>); +// iter_geo_impl_scalar!(MultiLineStringArray, LineString<'a>); +// iter_geo_impl_scalar!(MultiLineStringArray, Polygon<'a>); +// iter_geo_impl_scalar!(MultiLineStringArray, MultiPoint<'a>); +// iter_geo_impl_scalar!(MultiLineStringArray, MultiLineString<'a>); +// iter_geo_impl_scalar!(MultiLineStringArray, MultiPolygon<'a>); // Implementations on MultiPolygonArray -iter_geo_impl_scalar!(MultiPolygonArray, Point<'a, 2>); -// iter_geo_impl_scalar!(MultiPolygonArray, LineString<'a, 2>); -// iter_geo_impl_scalar!(MultiPolygonArray, Polygon<'a, 2>); -// iter_geo_impl_scalar!(MultiPolygonArray, MultiPoint<'a, 2>); -// iter_geo_impl_scalar!(MultiPolygonArray, MultiLineString<'a, 2>); -// iter_geo_impl_scalar!(MultiPolygonArray, MultiPolygon<'a, 2>); +iter_geo_impl_scalar!(MultiPolygonArray, Point<'a>); +// iter_geo_impl_scalar!(MultiPolygonArray, LineString<'a>); +// iter_geo_impl_scalar!(MultiPolygonArray, Polygon<'a>); +// iter_geo_impl_scalar!(MultiPolygonArray, MultiPoint<'a>); +// iter_geo_impl_scalar!(MultiPolygonArray, MultiLineString<'a>); +// iter_geo_impl_scalar!(MultiPolygonArray, MultiPolygon<'a>); diff --git a/rust/geoarrow/src/algorithm/geo/within.rs b/rust/geoarrow/src/algorithm/geo/within.rs index d7be79af..20eeea51 100644 --- a/rust/geoarrow/src/algorithm/geo/within.rs +++ b/rust/geoarrow/src/algorithm/geo/within.rs @@ -142,8 +142,8 @@ iter_geo_impl!(MultiPolygonArray, MultiPolygonArray); // └──────────────────────────────────────────┘ // Note: this implementation is outside the macro because it is not generic over O -impl<'a> Within> for PointArray { - fn is_within(&self, rhs: &Point<'a, 2>) -> BooleanArray { +impl<'a> Within> for PointArray { + fn is_within(&self, rhs: &Point<'a>) -> BooleanArray { let mut output_array = BooleanBuilder::with_capacity(self.len()); self.iter_geo().for_each(|maybe_point| { @@ -175,51 +175,51 @@ macro_rules! iter_geo_impl_geoarrow_scalar { } // Implementations on PointArray -iter_geo_impl_geoarrow_scalar!(PointArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PointArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PointArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PointArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PointArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(PointArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(PointArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(PointArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(PointArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(PointArray, MultiPolygon<'a>); // Implementations on LineStringArray -iter_geo_impl_geoarrow_scalar!(LineStringArray, Point<'a, 2>); -iter_geo_impl_geoarrow_scalar!(LineStringArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(LineStringArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, Point<'a>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(LineStringArray, MultiPolygon<'a>); // Implementations on PolygonArray -iter_geo_impl_geoarrow_scalar!(PolygonArray, Point<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PolygonArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PolygonArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, Point<'a>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(PolygonArray, MultiPolygon<'a>); // Implementations on MultiPointArray -iter_geo_impl_geoarrow_scalar!(MultiPointArray, Point<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPointArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPointArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, Point<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPointArray, MultiPolygon<'a>); // Implementations on MultiLineStringArray -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Point<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Point<'a>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiLineStringArray, MultiPolygon<'a>); // Implementations on MultiPolygonArray -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Point<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, LineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Polygon<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPoint<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiLineString<'a, 2>); -iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPolygon<'a, 2>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Point<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, LineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, Polygon<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPoint<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiLineString<'a>); +iter_geo_impl_geoarrow_scalar!(MultiPolygonArray, MultiPolygon<'a>); // ┌─────────────────────────────────────┐ // │ Implementations for RHS geo scalars │ diff --git a/rust/geoarrow/src/algorithm/native/explode.rs b/rust/geoarrow/src/algorithm/native/explode.rs index 36fc2536..11952486 100644 --- a/rust/geoarrow/src/algorithm/native/explode.rs +++ b/rust/geoarrow/src/algorithm/native/explode.rs @@ -22,7 +22,7 @@ pub trait Explode { fn explode(&self) -> Self::Output; } -impl Explode for PointArray<2> { +impl Explode for PointArray { type Output = (Self, Option); fn explode(&self) -> Self::Output { @@ -30,7 +30,7 @@ impl Explode for PointArray<2> { } } -impl Explode for LineStringArray<2> { +impl Explode for LineStringArray { type Output = (Self, Option); fn explode(&self) -> Self::Output { @@ -38,7 +38,7 @@ impl Explode for LineStringArray<2> { } } -impl Explode for PolygonArray<2> { +impl Explode for PolygonArray { type Output = (Self, Option); fn explode(&self) -> Self::Output { @@ -67,8 +67,8 @@ fn explode_offsets(offsets: &OffsetBuffer) -> Int32Array { Int32Array::new(take_indices.into(), None) } -impl Explode for MultiPointArray<2> { - type Output = (PointArray<2>, Option); +impl Explode for MultiPointArray { + type Output = (PointArray, Option); fn explode(&self) -> Self::Output { assert_eq!( @@ -83,8 +83,8 @@ impl Explode for MultiPointArray<2> { } } -impl Explode for MultiLineStringArray<2> { - type Output = (LineStringArray<2>, Option); +impl Explode for MultiLineStringArray { + type Output = (LineStringArray, Option); fn explode(&self) -> Self::Output { assert_eq!( @@ -104,8 +104,8 @@ impl Explode for MultiLineStringArray<2> { } } -impl Explode for MultiPolygonArray<2> { - type Output = (PolygonArray<2>, Option); +impl Explode for MultiPolygonArray { + type Output = (PolygonArray, Option); fn explode(&self) -> Self::Output { assert_eq!( @@ -147,8 +147,8 @@ impl Explode for &dyn NativeArray { MultiPoint(_, XY) => call_explode!(as_multi_point), MultiLineString(_, XY) => call_explode!(as_multi_line_string), MultiPolygon(_, XY) => call_explode!(as_multi_polygon), - // Mixed(_, XY) => self.as_mixed::<2>().explode(), - // GeometryCollection(_, XY) => self.as_geometry_collection::<2>().explode(), + // Mixed(_, XY) => self.as_mixed::().explode(), + // GeometryCollection(_, XY) => self.as_geometry_collection::().explode(), _ => return Err(GeoArrowError::IncorrectType("".into())), }; Ok(result) @@ -192,15 +192,15 @@ impl Explode for &dyn ChunkedNativeArray { use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().explode(), - LineString(_, XY) => self.as_line_string::<2>().explode(), - Polygon(_, XY) => self.as_polygon::<2>().explode(), - MultiPoint(_, XY) => self.as_multi_point::<2>().explode(), - MultiLineString(_, XY) => self.as_multi_line_string::<2>().explode(), - MultiPolygon(_, XY) => self.as_multi_polygon::<2>().explode(), - Mixed(_, XY) => self.as_mixed::<2>().explode(), - GeometryCollection(_, XY) => self.as_geometry_collection::<2>().explode(), - Rect(XY) => self.as_rect::<2>().explode(), + Point(_, XY) => self.as_point::().explode(), + LineString(_, XY) => self.as_line_string::().explode(), + Polygon(_, XY) => self.as_polygon::().explode(), + MultiPoint(_, XY) => self.as_multi_point::().explode(), + MultiLineString(_, XY) => self.as_multi_line_string::().explode(), + MultiPolygon(_, XY) => self.as_multi_polygon::().explode(), + Mixed(_, XY) => self.as_mixed::().explode(), + GeometryCollection(_, XY) => self.as_geometry_collection::().explode(), + Rect(XY) => self.as_rect::().explode(), _ => todo!(), } } diff --git a/rust/geoarrow/src/algorithm/native/type_id.rs b/rust/geoarrow/src/algorithm/native/type_id.rs index 2cfaf689..b9866afb 100644 --- a/rust/geoarrow/src/algorithm/native/type_id.rs +++ b/rust/geoarrow/src/algorithm/native/type_id.rs @@ -37,7 +37,7 @@ pub trait TypeIds { fn get_unique_type_ids(&self) -> HashSet; } -impl TypeIds for PointArray<2> { +impl TypeIds for PointArray { fn get_type_ids(&self) -> Int16Array { let values = vec![0i16; self.len()]; Int16Array::new(values.into(), self.nulls().cloned()) @@ -67,13 +67,13 @@ macro_rules! constant_impl { }; } -constant_impl!(LineStringArray<2>, 1); -constant_impl!(PolygonArray<2>, 3); -constant_impl!(MultiPointArray<2>, 4); -constant_impl!(MultiLineStringArray<2>, 5); -constant_impl!(MultiPolygonArray<2>, 6); +constant_impl!(LineStringArray, 1); +constant_impl!(PolygonArray, 3); +constant_impl!(MultiPointArray, 4); +constant_impl!(MultiLineStringArray, 5); +constant_impl!(MultiPolygonArray, 6); -impl TypeIds for MixedGeometryArray<2> { +impl TypeIds for MixedGeometryArray { fn get_type_ids(&self) -> Int16Array { use crate::scalar::Geometry::*; diff --git a/rust/geoarrow/src/array/dynamic.rs b/rust/geoarrow/src/array/dynamic.rs index 3afe16d6..90784fce 100644 --- a/rust/geoarrow/src/array/dynamic.rs +++ b/rust/geoarrow/src/array/dynamic.rs @@ -11,7 +11,7 @@ use crate::array::metadata::ArrayMetadata; use crate::array::wkt::WKTArray; use crate::array::CoordType; use crate::array::*; -use crate::datatypes::{Dimension, NativeType, SerializedType}; +use crate::datatypes::{NativeType, SerializedType}; use crate::error::Result; use crate::trait_::{NativeArrayRef, SerializedArray, SerializedArrayRef}; use crate::{ArrayBase, NativeArray}; @@ -29,45 +29,19 @@ impl NativeArrayDyn { pub fn from_arrow_array(array: &dyn Array, field: &Field) -> Result { let data_type = NativeType::try_from(field)?; - use Dimension::*; use NativeType::*; let geo_arr: Arc = match data_type { - Point(_, dim) => match dim { - XY => Arc::new(PointArray::try_from((array, field))?), - XYZ => Arc::new(PointArray::<3>::try_from((array, field))?), - }, - LineString(_, dim) => match dim { - XY => Arc::new(LineStringArray::try_from((array, field))?), - XYZ => Arc::new(LineStringArray::<3>::try_from((array, field))?), - }, - Polygon(_, dim) => match dim { - XY => Arc::new(PolygonArray::try_from((array, field))?), - XYZ => Arc::new(PolygonArray::<3>::try_from((array, field))?), - }, - MultiPoint(_, dim) => match dim { - XY => Arc::new(MultiPointArray::try_from((array, field))?), - XYZ => Arc::new(MultiPointArray::<3>::try_from((array, field))?), - }, - MultiLineString(_, dim) => match dim { - XY => Arc::new(MultiLineStringArray::try_from((array, field))?), - XYZ => Arc::new(MultiLineStringArray::<3>::try_from((array, field))?), - }, - MultiPolygon(_, dim) => match dim { - XY => Arc::new(MultiPolygonArray::try_from((array, field))?), - XYZ => Arc::new(MultiPolygonArray::<3>::try_from((array, field))?), - }, - Mixed(_, dim) => match dim { - XY => Arc::new(MixedGeometryArray::try_from((array, field))?), - XYZ => Arc::new(MixedGeometryArray::<3>::try_from((array, field))?), - }, - GeometryCollection(_, dim) => match dim { - XY => Arc::new(GeometryCollectionArray::try_from((array, field))?), - XYZ => Arc::new(GeometryCollectionArray::<3>::try_from((array, field))?), - }, - Rect(dim) => match dim { - XY => Arc::new(RectArray::try_from((array, field))?), - XYZ => Arc::new(RectArray::<3>::try_from((array, field))?), - }, + Point(_, _) => Arc::new(PointArray::try_from((array, field))?), + LineString(_, _) => Arc::new(LineStringArray::try_from((array, field))?), + Polygon(_, _) => Arc::new(PolygonArray::try_from((array, field))?), + MultiPoint(_, _) => Arc::new(MultiPointArray::try_from((array, field))?), + MultiLineString(_, _) => Arc::new(MultiLineStringArray::try_from((array, field))?), + MultiPolygon(_, _) => Arc::new(MultiPolygonArray::try_from((array, field))?), + Mixed(_, _) => Arc::new(MixedGeometryArray::try_from((array, field))?), + GeometryCollection(_, _) => { + Arc::new(GeometryCollectionArray::try_from((array, field))?) + } + Rect(_) => Arc::new(RectArray::try_from((array, field))?), }; Ok(Self(geo_arr)) diff --git a/rust/geoarrow/src/array/linestring/array.rs b/rust/geoarrow/src/array/linestring/array.rs index 11a1a69b..eb4c6e17 100644 --- a/rust/geoarrow/src/array/linestring/array.rs +++ b/rust/geoarrow/src/array/linestring/array.rs @@ -411,15 +411,15 @@ impl TryFrom<(&dyn Array, &Field)> for LineStringArray { } } -impl> From>> for LineStringArray { - fn from(other: Vec>) -> Self { +impl> From<(Vec>, Dimension)> for LineStringArray { + fn from(other: (Vec>, Dimension)) -> Self { let mut_arr: LineStringBuilder = other.into(); mut_arr.into() } } -impl> From<&[G]> for LineStringArray { - fn from(other: &[G]) -> Self { +impl> From<(&[G], Dimension)> for LineStringArray { + fn from(other: (&[G], Dimension)) -> Self { let mut_arr: LineStringBuilder = other.into(); mut_arr.into() } @@ -515,6 +515,7 @@ impl TryFrom for LineStringArray { capacity.geom_capacity += buffer_lengths.ring_capacity; let mut builder = LineStringBuilder::with_capacity_and_options( + value.dim(), capacity, value.coord_type(), value.metadata(), diff --git a/rust/geoarrow/src/array/linestring/builder.rs b/rust/geoarrow/src/array/linestring/builder.rs index 05b8c941..d925f025 100644 --- a/rust/geoarrow/src/array/linestring/builder.rs +++ b/rust/geoarrow/src/array/linestring/builder.rs @@ -6,6 +6,7 @@ use crate::array::{ CoordBufferBuilder, CoordType, InterleavedCoordBufferBuilder, LineStringArray, MultiPointBuilder, SeparatedCoordBufferBuilder, WKBArray, }; +use crate::datatypes::Dimension; use crate::error::{GeoArrowError, Result}; use crate::scalar::WKB; use crate::trait_::{ArrayAccessor, GeometryArrayBuilder, IntoArrow}; @@ -33,37 +34,36 @@ pub struct LineStringBuilder { impl LineStringBuilder { /// Creates a new empty [`LineStringBuilder`]. - pub fn new() -> Self { - Self::new_with_options(Default::default(), Default::default()) + pub fn new(dim: Dimension) -> Self { + Self::new_with_options(dim, Default::default(), Default::default()) } - pub fn new_with_options(coord_type: CoordType, metadata: Arc) -> Self { - Self::with_capacity_and_options(Default::default(), coord_type, metadata) + pub fn new_with_options( + dim: Dimension, + coord_type: CoordType, + metadata: Arc, + ) -> Self { + Self::with_capacity_and_options(dim, Default::default(), coord_type, metadata) } /// Creates a new [`LineStringBuilder`] with a capacity. - pub fn with_capacity(capacity: LineStringCapacity) -> Self { - Self::with_capacity_and_options(capacity, Default::default(), Default::default()) + pub fn with_capacity(dim: Dimension, capacity: LineStringCapacity) -> Self { + Self::with_capacity_and_options(dim, capacity, Default::default(), Default::default()) } pub fn with_capacity_and_options( + dim: Dimension, capacity: LineStringCapacity, coord_type: CoordType, metadata: Arc, ) -> Self { let coords = match coord_type { - CoordType::Interleaved => { - CoordBufferBuilder::Interleaved(InterleavedCoordBufferBuilder::with_capacity( - capacity.coord_capacity(), - D.try_into().unwrap(), - )) - } - CoordType::Separated => { - CoordBufferBuilder::Separated(SeparatedCoordBufferBuilder::with_capacity( - capacity.coord_capacity(), - D.try_into().unwrap(), - )) - } + CoordType::Interleaved => CoordBufferBuilder::Interleaved( + InterleavedCoordBufferBuilder::with_capacity(capacity.coord_capacity(), dim), + ), + CoordType::Separated => CoordBufferBuilder::Separated( + SeparatedCoordBufferBuilder::with_capacity(capacity.coord_capacity(), dim), + ), }; Self { coords, @@ -161,17 +161,24 @@ impl LineStringBuilder { pub fn with_capacity_from_iter<'a>( geoms: impl Iterator>, + dim: Dimension, ) -> Self { - Self::with_capacity_and_options_from_iter(geoms, Default::default(), Default::default()) + Self::with_capacity_and_options_from_iter( + geoms, + dim, + Default::default(), + Default::default(), + ) } pub fn with_capacity_and_options_from_iter<'a>( geoms: impl Iterator>, + dim: Dimension, coord_type: CoordType, metadata: Arc, ) -> Self { let counter = LineStringCapacity::from_line_strings(geoms); - Self::with_capacity_and_options(counter, coord_type, metadata) + Self::with_capacity_and_options(dim, counter, coord_type, metadata) } pub fn reserve_from_iter<'a>( @@ -192,11 +199,13 @@ impl LineStringBuilder { pub fn from_line_strings( geoms: &[impl LineStringTrait], + dim: Dimension, coord_type: Option, metadata: Arc, ) -> Self { let mut array = Self::with_capacity_and_options_from_iter( geoms.iter().map(Some), + dim, coord_type.unwrap_or_default(), metadata, ); @@ -206,11 +215,13 @@ impl LineStringBuilder { pub fn from_nullable_line_strings( geoms: &[Option>], + dim: Dimension, coord_type: Option, metadata: Arc, ) -> Self { let mut array = Self::with_capacity_and_options_from_iter( geoms.iter().map(|x| x.as_ref()), + dim, coord_type.unwrap_or_default(), metadata, ); @@ -290,18 +301,24 @@ impl LineStringBuilder { } pub fn from_nullable_geometries( + dim: Dimension, geoms: &[Option>], coord_type: Option, metadata: Arc, ) -> Result { let capacity = LineStringCapacity::from_geometries(geoms.iter().map(|x| x.as_ref()))?; - let mut array = - Self::with_capacity_and_options(capacity, coord_type.unwrap_or_default(), metadata); + let mut array = Self::with_capacity_and_options( + dim, + capacity, + coord_type.unwrap_or_default(), + metadata, + ); array.extend_from_geometry_iter(geoms.iter().map(|x| x.as_ref()))?; Ok(array) } pub(crate) fn from_wkb( + dim: Dimension, wkb_objects: &[Option>], coord_type: Option, metadata: Arc, @@ -310,22 +327,23 @@ impl LineStringBuilder { .iter() .map(|maybe_wkb| maybe_wkb.as_ref().map(|wkb| wkb.parse()).transpose()) .collect::>>()?; - Self::from_nullable_geometries(&wkb_objects2, coord_type, metadata) + Self::from_nullable_geometries(dim, &wkb_objects2, coord_type, metadata) } } impl GeometryArrayBuilder for LineStringBuilder { - fn new() -> Self { - Self::new() + fn new(dim: Dimension) -> Self { + Self::new(dim) } fn with_geom_capacity_and_options( + dim: Dimension, geom_capacity: usize, coord_type: CoordType, metadata: Arc, ) -> Self { let capacity = LineStringCapacity::new(0, geom_capacity); - Self::with_capacity_and_options(capacity, coord_type, metadata) + Self::with_capacity_and_options(dim, capacity, coord_type, metadata) } fn push_geometry(&mut self, value: Option<&impl GeometryTrait>) -> Result<()> { @@ -372,7 +390,7 @@ impl IntoArrow for LineStringBuilder { impl Default for LineStringBuilder { fn default() -> Self { - Self::new() + LineStringBuilder::new(Dimension::XY) } } @@ -394,15 +412,15 @@ impl From for GenericListArray { } } -impl> From<&[G]> for LineStringBuilder { - fn from(geoms: &[G]) -> Self { - Self::from_line_strings(geoms, Default::default(), Default::default()) +impl> From<(&[G], Dimension)> for LineStringBuilder { + fn from((geoms, dim): (&[G], Dimension)) -> Self { + Self::from_line_strings(geoms, dim, Default::default(), Default::default()) } } -impl> From>> for LineStringBuilder { - fn from(geoms: Vec>) -> Self { - Self::from_nullable_line_strings(&geoms, Default::default(), Default::default()) +impl> From<(Vec>, Dimension)> for LineStringBuilder { + fn from((geoms, dim): (Vec>, Dimension)) -> Self { + Self::from_nullable_line_strings(&geoms, dim, Default::default(), Default::default()) } } diff --git a/rust/geoarrow/src/array/multilinestring/array.rs b/rust/geoarrow/src/array/multilinestring/array.rs index 2eb5064d..6a32eb6f 100644 --- a/rust/geoarrow/src/array/multilinestring/array.rs +++ b/rust/geoarrow/src/array/multilinestring/array.rs @@ -464,15 +464,15 @@ impl TryFrom<(&dyn Array, &Field)> for MultiLineStringArray { } } -impl> From>> for MultiLineStringArray { - fn from(other: Vec>) -> Self { +impl> From<(Vec>, Dimension)> for MultiLineStringArray { + fn from(other: (Vec>, Dimension)) -> Self { let mut_arr: MultiLineStringBuilder = other.into(); mut_arr.into() } } -impl> From<&[G]> for MultiLineStringArray { - fn from(other: &[G]) -> Self { +impl> From<(&[G], Dimension)> for MultiLineStringArray { + fn from(other: (&[G], Dimension)) -> Self { let mut_arr: MultiLineStringBuilder = other.into(); mut_arr.into() } diff --git a/rust/geoarrow/src/array/multilinestring/builder.rs b/rust/geoarrow/src/array/multilinestring/builder.rs index 64d05367..023b6388 100644 --- a/rust/geoarrow/src/array/multilinestring/builder.rs +++ b/rust/geoarrow/src/array/multilinestring/builder.rs @@ -59,7 +59,7 @@ impl MultiLineStringBuilder { /// Creates a new [`MultiLineStringBuilder`] with a capacity. pub fn with_capacity(dim: Dimension, capacity: MultiLineStringCapacity) -> Self { - Self::with_capacity_and_options(capacity, Default::default(), Default::default()) + Self::with_capacity_and_options(dim, capacity, Default::default(), Default::default()) } pub fn with_capacity_and_options( @@ -193,17 +193,24 @@ impl MultiLineStringBuilder { pub fn with_capacity_from_iter<'a>( geoms: impl Iterator>, + dim: Dimension, ) -> Self { - Self::with_capacity_and_options_from_iter(geoms, Default::default(), Default::default()) + Self::with_capacity_and_options_from_iter( + geoms, + dim, + Default::default(), + Default::default(), + ) } pub fn with_capacity_and_options_from_iter<'a>( geoms: impl Iterator>, + dim: Dimension, coord_type: CoordType, metadata: Arc, ) -> Self { let counter = MultiLineStringCapacity::from_multi_line_strings(geoms); - Self::with_capacity_and_options(counter, coord_type, metadata) + Self::with_capacity_and_options(dim, counter, coord_type, metadata) } pub fn reserve_from_iter<'a>( @@ -349,11 +356,13 @@ impl MultiLineStringBuilder { pub fn from_multi_line_strings( geoms: &[impl MultiLineStringTrait], + dim: Dimension, coord_type: Option, metadata: Arc, ) -> Self { let mut array = Self::with_capacity_and_options_from_iter( geoms.iter().map(Some), + dim, coord_type.unwrap_or_default(), metadata, ); @@ -363,11 +372,13 @@ impl MultiLineStringBuilder { pub fn from_nullable_multi_line_strings( geoms: &[Option>], + dim: Dimension, coord_type: Option, metadata: Arc, ) -> Self { let mut array = Self::with_capacity_and_options_from_iter( geoms.iter().map(|x| x.as_ref()), + dim, coord_type.unwrap_or_default(), metadata, ); @@ -377,12 +388,17 @@ impl MultiLineStringBuilder { pub fn from_nullable_geometries( geoms: &[Option>], + dim: Dimension, coord_type: Option, metadata: Arc, ) -> Result { let capacity = MultiLineStringCapacity::from_geometries(geoms.iter().map(|x| x.as_ref()))?; - let mut array = - Self::with_capacity_and_options(capacity, coord_type.unwrap_or_default(), metadata); + let mut array = Self::with_capacity_and_options( + dim, + capacity, + coord_type.unwrap_or_default(), + metadata, + ); array.extend_from_geometry_iter(geoms.iter().map(|x| x.as_ref()))?; Ok(array) } @@ -401,17 +417,18 @@ impl MultiLineStringBuilder { } impl GeometryArrayBuilder for MultiLineStringBuilder { - fn new() -> Self { - Self::new() + fn new(dim: Dimension) -> Self { + Self::new(dim) } fn with_geom_capacity_and_options( + dim: Dimension, geom_capacity: usize, coord_type: CoordType, metadata: Arc, ) -> Self { let capacity = MultiLineStringCapacity::new(0, 0, geom_capacity); - Self::with_capacity_and_options(capacity, coord_type, metadata) + Self::with_capacity_and_options(dim, capacity, coord_type, metadata) } fn push_geometry(&mut self, value: Option<&impl GeometryTrait>) -> Result<()> { @@ -458,7 +475,7 @@ impl IntoArrow for MultiLineStringBuilder { impl Default for MultiLineStringBuilder { fn default() -> Self { - Self::new() + Self::new(Dimension::XY) } } @@ -479,15 +496,17 @@ impl From for MultiLineStringArray { } } -impl> From<&[G]> for MultiLineStringBuilder { - fn from(geoms: &[G]) -> Self { - Self::from_multi_line_strings(geoms, Default::default(), Default::default()) +impl> From<(&[G], Dimension)> for MultiLineStringBuilder { + fn from((geoms, dim): (&[G], Dimension)) -> Self { + Self::from_multi_line_strings(geoms, dim, Default::default(), Default::default()) } } -impl> From>> for MultiLineStringBuilder { - fn from(geoms: Vec>) -> Self { - Self::from_nullable_multi_line_strings(&geoms, Default::default(), Default::default()) +impl> From<(Vec>, Dimension)> + for MultiLineStringBuilder +{ + fn from((geoms, dim): (Vec>, Dimension)) -> Self { + Self::from_nullable_multi_line_strings(&geoms, dim, Default::default(), Default::default()) } } diff --git a/rust/geoarrow/src/chunked_array/dynamic.rs b/rust/geoarrow/src/chunked_array/dynamic.rs index b2f24db0..bff97c9d 100644 --- a/rust/geoarrow/src/chunked_array/dynamic.rs +++ b/rust/geoarrow/src/chunked_array/dynamic.rs @@ -6,7 +6,7 @@ use arrow_schema::Field; use crate::array::*; use crate::chunked_array::{ChunkedGeometryArray, ChunkedNativeArray}; -use crate::datatypes::{Dimension, NativeType}; +use crate::datatypes::NativeType; use crate::error::{GeoArrowError, Result}; /// A wrapper around a ChunkedNativeArray of unknown type @@ -30,7 +30,7 @@ impl ChunkedNativeArrayDyn { /// use geoarrow::chunked_array::ChunkedNativeArrayDyn; /// use std::sync::Arc; /// - /// let array: PointArray<2> = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); + /// let array: PointArray = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); /// let field = array.extension_field(); /// let array = array.into_array_ref(); /// let chunks = vec![array.as_ref()]; @@ -57,29 +57,17 @@ impl ChunkedNativeArrayDyn { let typ = NativeType::try_from(field)?; let ca: Arc = match typ { - Point(_, Dimension::XY) => impl_downcast!(PointArray<2>), - LineString(_, Dimension::XY) => impl_downcast!(LineStringArray<2>), - Polygon(_, Dimension::XY) => impl_downcast!(PolygonArray<2>), - MultiPoint(_, Dimension::XY) => impl_downcast!(MultiPointArray<2>), - MultiLineString(_, Dimension::XY) => impl_downcast!(MultiLineStringArray<2>), - MultiPolygon(_, Dimension::XY) => impl_downcast!(MultiPolygonArray<2>), - Mixed(_, Dimension::XY) => impl_downcast!(MixedGeometryArray<2>), - GeometryCollection(_, Dimension::XY) => { - impl_downcast!(GeometryCollectionArray<2>) + Point(_, _) => impl_downcast!(PointArray), + LineString(_, _) => impl_downcast!(LineStringArray), + Polygon(_, _) => impl_downcast!(PolygonArray), + MultiPoint(_, _) => impl_downcast!(MultiPointArray), + MultiLineString(_, _) => impl_downcast!(MultiLineStringArray), + MultiPolygon(_, _) => impl_downcast!(MultiPolygonArray), + Mixed(_, _) => impl_downcast!(MixedGeometryArray), + GeometryCollection(_, _) => { + impl_downcast!(GeometryCollectionArray) } - Rect(Dimension::XY) => impl_downcast!(RectArray<2>), - - Point(_, Dimension::XYZ) => impl_downcast!(PointArray<3>), - LineString(_, Dimension::XYZ) => impl_downcast!(LineStringArray<3>), - Polygon(_, Dimension::XYZ) => impl_downcast!(PolygonArray<3>), - MultiPoint(_, Dimension::XYZ) => impl_downcast!(MultiPointArray<3>), - MultiLineString(_, Dimension::XYZ) => impl_downcast!(MultiLineStringArray<3>), - MultiPolygon(_, Dimension::XYZ) => impl_downcast!(MultiPolygonArray<3>), - Mixed(_, Dimension::XYZ) => impl_downcast!(MixedGeometryArray<3>), - GeometryCollection(_, Dimension::XYZ) => { - impl_downcast!(GeometryCollectionArray<3>) - } - Rect(Dimension::XYZ) => impl_downcast!(RectArray<3>), + Rect(_) => impl_downcast!(RectArray), }; Ok(Self(ca)) } @@ -92,8 +80,8 @@ impl ChunkedNativeArrayDyn { /// use geoarrow::{NativeArray, array::PointArray}; /// use geoarrow::chunked_array::ChunkedNativeArrayDyn; /// - /// 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 array_0: PointArray = vec![&geo::point!(x: 1., y: 2.)].as_slice().into(); + /// let array_1: PointArray = vec![&geo::point!(x: 3., y: 4.)].as_slice().into(); /// let chunks = vec![array_0.as_ref(), array_1.as_ref()]; /// let chunked_array = ChunkedNativeArrayDyn::from_geoarrow_chunks(chunks.as_slice()).unwrap(); /// ``` @@ -111,11 +99,11 @@ impl ChunkedNativeArrayDyn { if data_types.len() == 1 { macro_rules! impl_downcast { - ($cast_func:ident, $dim:expr) => { + ($cast_func:ident) => { Arc::new(ChunkedGeometryArray::new( chunks .iter() - .map(|chunk| chunk.as_ref().$cast_func::<$dim>().clone()) + .map(|chunk| chunk.as_ref().$cast_func().clone()) .collect(), )) }; @@ -123,24 +111,15 @@ impl ChunkedNativeArrayDyn { use NativeType::*; let result: Arc = match data_types.drain().next().unwrap() { - Point(_, Dimension::XY) => impl_downcast!(as_point, 2), - LineString(_, Dimension::XY) => impl_downcast!(as_line_string, 2), - Polygon(_, Dimension::XY) => impl_downcast!(as_polygon, 2), - MultiPoint(_, Dimension::XY) => impl_downcast!(as_multi_point, 2), - MultiLineString(_, Dimension::XY) => impl_downcast!(as_multi_line_string, 2), - MultiPolygon(_, Dimension::XY) => impl_downcast!(as_multi_polygon, 2), - Mixed(_, Dimension::XY) => impl_downcast!(as_mixed, 2), - GeometryCollection(_, Dimension::XY) => impl_downcast!(as_geometry_collection, 2), - Point(_, Dimension::XYZ) => impl_downcast!(as_point, 3), - LineString(_, Dimension::XYZ) => impl_downcast!(as_line_string, 3), - Polygon(_, Dimension::XYZ) => impl_downcast!(as_polygon, 3), - MultiPoint(_, Dimension::XYZ) => impl_downcast!(as_multi_point, 3), - MultiLineString(_, Dimension::XYZ) => impl_downcast!(as_multi_line_string, 3), - MultiPolygon(_, Dimension::XYZ) => impl_downcast!(as_multi_polygon, 3), - Mixed(_, Dimension::XYZ) => impl_downcast!(as_mixed, 3), - GeometryCollection(_, Dimension::XYZ) => impl_downcast!(as_geometry_collection, 3), - Rect(Dimension::XY) => impl_downcast!(as_rect, 2), - Rect(Dimension::XYZ) => impl_downcast!(as_rect, 3), + Point(_, _) => impl_downcast!(as_point), + LineString(_, _) => impl_downcast!(as_line_string), + Polygon(_, _) => impl_downcast!(as_polygon), + MultiPoint(_, _) => impl_downcast!(as_multi_point), + MultiLineString(_, _) => impl_downcast!(as_multi_line_string), + MultiPolygon(_, _) => impl_downcast!(as_multi_polygon), + Mixed(_, _) => impl_downcast!(as_mixed), + GeometryCollection(_, _) => impl_downcast!(as_geometry_collection), + Rect(_) => impl_downcast!(as_rect), }; Ok(Self(result)) } else { diff --git a/rust/geoarrow/src/chunked_array/mod.rs b/rust/geoarrow/src/chunked_array/mod.rs index 087f6dee..ec8c0b54 100644 --- a/rust/geoarrow/src/chunked_array/mod.rs +++ b/rust/geoarrow/src/chunked_array/mod.rs @@ -568,25 +568,23 @@ impl TryFrom> for ChunkedGeometryArray { } /// A chunked point array. -pub type ChunkedPointArray = ChunkedGeometryArray>; +pub type ChunkedPointArray = ChunkedGeometryArray; /// A chunked line string array. -pub type ChunkedLineStringArray = ChunkedGeometryArray>; +pub type ChunkedLineStringArray = ChunkedGeometryArray; /// A chunked polygon array. -pub type ChunkedPolygonArray = ChunkedGeometryArray>; +pub type ChunkedPolygonArray = ChunkedGeometryArray; /// A chunked multi-point array. -pub type ChunkedMultiPointArray = ChunkedGeometryArray>; +pub type ChunkedMultiPointArray = ChunkedGeometryArray; /// A chunked mutli-line string array. -pub type ChunkedMultiLineStringArray = - ChunkedGeometryArray>; +pub type ChunkedMultiLineStringArray = ChunkedGeometryArray; /// A chunked multi-polygon array. -pub type ChunkedMultiPolygonArray = ChunkedGeometryArray>; +pub type ChunkedMultiPolygonArray = ChunkedGeometryArray; /// A chunked mixed geometry array. -pub type ChunkedMixedGeometryArray = ChunkedGeometryArray>; +pub type ChunkedMixedGeometryArray = ChunkedGeometryArray; /// A chunked geometry collection array. -pub type ChunkedGeometryCollectionArray = - ChunkedGeometryArray>; +pub type ChunkedGeometryCollectionArray = ChunkedGeometryArray; /// A chunked rect array. -pub type ChunkedRectArray = ChunkedGeometryArray>; +pub type ChunkedRectArray = ChunkedGeometryArray; /// A chunked unknown geometry array. #[allow(dead_code)] pub type ChunkedUnknownGeometryArray = ChunkedGeometryArray>; @@ -797,7 +795,7 @@ pub trait ChunkedNativeArray: ChunkedArrayBase { } } -impl ChunkedArrayBase for ChunkedPointArray { +impl ChunkedArrayBase for ChunkedPointArray { fn as_any(&self) -> &dyn Any { self } @@ -823,7 +821,7 @@ impl ChunkedArrayBase for ChunkedPointArray { } } -impl ChunkedNativeArray for ChunkedPointArray { +impl ChunkedNativeArray for ChunkedPointArray { fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } @@ -930,15 +928,15 @@ macro_rules! impl_trait { }; } -impl_trait!(ChunkedLineStringArray); -impl_trait!(ChunkedPolygonArray); -impl_trait!(ChunkedMultiPointArray); -impl_trait!(ChunkedMultiLineStringArray); -impl_trait!(ChunkedMultiPolygonArray); -impl_trait!(ChunkedMixedGeometryArray); -impl_trait!(ChunkedGeometryCollectionArray); +impl_trait!(ChunkedLineStringArray); +impl_trait!(ChunkedPolygonArray); +impl_trait!(ChunkedMultiPointArray); +impl_trait!(ChunkedMultiLineStringArray); +impl_trait!(ChunkedMultiPolygonArray); +impl_trait!(ChunkedMixedGeometryArray); +impl_trait!(ChunkedGeometryCollectionArray); -impl ChunkedArrayBase for ChunkedRectArray { +impl ChunkedArrayBase for ChunkedRectArray { fn as_any(&self) -> &dyn Any { self } @@ -965,7 +963,7 @@ impl ChunkedArrayBase for ChunkedRectArray { } } -impl ChunkedNativeArray for ChunkedRectArray { +impl ChunkedNativeArray for ChunkedRectArray { fn data_type(&self) -> NativeType { self.chunks.first().unwrap().data_type() } diff --git a/rust/geoarrow/src/indexed/array.rs b/rust/geoarrow/src/indexed/array.rs index 72976db8..aac1f8b1 100644 --- a/rust/geoarrow/src/indexed/array.rs +++ b/rust/geoarrow/src/indexed/array.rs @@ -125,20 +125,18 @@ impl<'a, G: NativeArray + ArrayAccessor<'a>> IndexedGeometryArray { } } -pub type IndexedPointArray = IndexedGeometryArray>; -pub type IndexedLineStringArray = IndexedGeometryArray>; -pub type IndexedPolygonArray = IndexedGeometryArray>; -pub type IndexedMultiPointArray = IndexedGeometryArray>; -pub type IndexedMultiLineStringArray = - IndexedGeometryArray>; -pub type IndexedMultiPolygonArray = IndexedGeometryArray>; -pub type IndexedMixedGeometryArray = IndexedGeometryArray>; -pub type IndexedGeometryCollectionArray = - IndexedGeometryArray>; +pub type IndexedPointArray = IndexedGeometryArray; +pub type IndexedLineStringArray = IndexedGeometryArray; +pub type IndexedPolygonArray = IndexedGeometryArray; +pub type IndexedMultiPointArray = IndexedGeometryArray; +pub type IndexedMultiLineStringArray = IndexedGeometryArray; +pub type IndexedMultiPolygonArray = IndexedGeometryArray; +pub type IndexedMixedGeometryArray = IndexedGeometryArray; +pub type IndexedGeometryCollectionArray = IndexedGeometryArray; #[allow(dead_code)] pub type IndexedWKBArray = IndexedGeometryArray>; #[allow(dead_code)] -pub type IndexedRectArray = IndexedGeometryArray>; +pub type IndexedRectArray = IndexedGeometryArray; #[allow(dead_code)] pub type IndexedUnknownGeometryArray = IndexedGeometryArray>; diff --git a/rust/geoarrow/src/indexed/chunked.rs b/rust/geoarrow/src/indexed/chunked.rs index 7fe2d44e..d4c4ff47 100644 --- a/rust/geoarrow/src/indexed/chunked.rs +++ b/rust/geoarrow/src/indexed/chunked.rs @@ -42,24 +42,19 @@ impl IndexedChunkedGeometryArray { } } -pub type IndexedChunkedPointArray = IndexedChunkedGeometryArray>; -pub type IndexedChunkedLineStringArray = - IndexedChunkedGeometryArray>; -pub type IndexedChunkedPolygonArray = IndexedChunkedGeometryArray>; -pub type IndexedChunkedMultiPointArray = - IndexedChunkedGeometryArray>; -pub type IndexedChunkedMultiLineStringArray = - IndexedChunkedGeometryArray>; -pub type IndexedChunkedMultiPolygonArray = - IndexedChunkedGeometryArray>; -pub type IndexedChunkedMixedGeometryArray = - IndexedChunkedGeometryArray>; +pub type IndexedChunkedPointArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedLineStringArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedPolygonArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedMultiPointArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedMultiLineStringArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedMultiPolygonArray = IndexedChunkedGeometryArray; +pub type IndexedChunkedMixedGeometryArray = IndexedChunkedGeometryArray; pub type IndexedChunkedGeometryCollectionArray = - IndexedChunkedGeometryArray>; + IndexedChunkedGeometryArray; #[allow(dead_code)] pub type IndexedChunkedWKBArray = IndexedChunkedGeometryArray>; #[allow(dead_code)] -pub type IndexedChunkedRectArray = IndexedChunkedGeometryArray>; +pub type IndexedChunkedRectArray = IndexedChunkedGeometryArray; #[allow(dead_code)] pub type IndexedChunkedUnknownGeometryArray = IndexedChunkedGeometryArray>; diff --git a/rust/geoarrow/src/io/display/array.rs b/rust/geoarrow/src/io/display/array.rs index b5ba9f06..b1440773 100644 --- a/rust/geoarrow/src/io/display/array.rs +++ b/rust/geoarrow/src/io/display/array.rs @@ -78,8 +78,8 @@ macro_rules! impl_fmt_non_generic { }; } -impl_fmt_non_generic!(PointArray<2>, "PointArray"); -impl_fmt_non_generic!(RectArray<2>, "RectArray"); +impl_fmt_non_generic!(PointArray, "PointArray"); +impl_fmt_non_generic!(RectArray, "RectArray"); macro_rules! impl_fmt_generic { ($struct_name:ty, $str_literal:tt) => { @@ -122,22 +122,22 @@ macro_rules! impl_fmt_generic { }; } -impl_fmt_generic!(LineStringArray<2>, "LineStringArray"); -impl_fmt_generic!(PolygonArray<2>, "PolygonArray"); -impl_fmt_generic!(MultiPointArray<2>, "MultiPointArray"); -impl_fmt_generic!(MultiLineStringArray<2>, "MultiLineStringArray"); -impl_fmt_generic!(MultiPolygonArray<2>, "MultiPolygonArray"); -impl_fmt_generic!(MixedGeometryArray<2>, "MixedGeometryArray"); -impl_fmt_generic!(GeometryCollectionArray<2>, "GeometryCollectionArray"); +impl_fmt_generic!(LineStringArray, "LineStringArray"); +impl_fmt_generic!(PolygonArray, "PolygonArray"); +impl_fmt_generic!(MultiPointArray, "MultiPointArray"); +impl_fmt_generic!(MultiLineStringArray, "MultiLineStringArray"); +impl_fmt_generic!(MultiPolygonArray, "MultiPolygonArray"); +impl_fmt_generic!(MixedGeometryArray, "MixedGeometryArray"); +impl_fmt_generic!(GeometryCollectionArray, "GeometryCollectionArray"); // impl_fmt_generic!(WKBArray, "WKBArray"); -impl fmt::Display for PointArray<2> { +impl fmt::Display for PointArray { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.write(f, 0) } } -impl fmt::Display for RectArray<2> { +impl fmt::Display for RectArray { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.write(f, 0) } @@ -153,13 +153,13 @@ macro_rules! impl_fmt { }; } -impl_fmt!(LineStringArray<2>, "LineStringArray"); -impl_fmt!(PolygonArray<2>, "PolygonArray"); -impl_fmt!(MultiPointArray<2>, "MultiPointArray"); -impl_fmt!(MultiLineStringArray<2>, "MultiLineStringArray"); -impl_fmt!(MultiPolygonArray<2>, "MultiPolygonArray"); -impl_fmt!(MixedGeometryArray<2>, "MixedGeometryArray"); -impl_fmt!(GeometryCollectionArray<2>, "GeometryCollectionArray"); +impl_fmt!(LineStringArray, "LineStringArray"); +impl_fmt!(PolygonArray, "PolygonArray"); +impl_fmt!(MultiPointArray, "MultiPointArray"); +impl_fmt!(MultiLineStringArray, "MultiLineStringArray"); +impl_fmt!(MultiPolygonArray, "MultiPolygonArray"); +impl_fmt!(MixedGeometryArray, "MixedGeometryArray"); +impl_fmt!(GeometryCollectionArray, "GeometryCollectionArray"); // impl_fmt!(WKBArray, "WKBArray"); #[cfg(test)] diff --git a/rust/geoarrow/src/io/geos/array/geometrycollection.rs b/rust/geoarrow/src/io/geos/array/geometrycollection.rs index d88d1201..3a912d35 100644 --- a/rust/geoarrow/src/io/geos/array/geometrycollection.rs +++ b/rust/geoarrow/src/io/geos/array/geometrycollection.rs @@ -2,7 +2,7 @@ use crate::array::{GeometryCollectionArray, GeometryCollectionBuilder}; use crate::error::GeoArrowError; use crate::io::geos::scalar::GEOSGeometryCollection; -impl TryFrom> for GeometryCollectionBuilder { +impl TryFrom> for GeometryCollectionBuilder { type Error = GeoArrowError; fn try_from(value: Vec) -> std::result::Result { @@ -14,11 +14,11 @@ impl TryFrom> for GeometryCollectionBuilder { } } -impl TryFrom> for GeometryCollectionArray { +impl TryFrom> for GeometryCollectionArray { type Error = GeoArrowError; fn try_from(value: Vec) -> std::result::Result { - let mutable_arr: GeometryCollectionBuilder = value.try_into()?; + let mutable_arr: GeometryCollectionBuilder = value.try_into()?; Ok(mutable_arr.into()) } } diff --git a/rust/geoarrow/src/io/geos/array/linestring.rs b/rust/geoarrow/src/io/geos/array/linestring.rs index 95909857..a0402be7 100644 --- a/rust/geoarrow/src/io/geos/array/linestring.rs +++ b/rust/geoarrow/src/io/geos/array/linestring.rs @@ -2,7 +2,7 @@ use crate::array::{LineStringArray, LineStringBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSLineString; -impl LineStringBuilder { +impl LineStringBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_objects: Vec> = value @@ -13,7 +13,7 @@ impl LineStringBuilder { } } -impl LineStringArray { +impl LineStringArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = LineStringBuilder::from_geos(value)?; Ok(mutable_arr.into()) @@ -34,7 +34,7 @@ mod test { .iter() .map(|opt_x| opt_x.map(|x| x.to_geos().unwrap())) .collect(); - let round_trip = LineStringArray::<2>::from_geos(geos_geoms).unwrap(); + let round_trip = LineStringArray::from_geos(geos_geoms).unwrap(); assert_eq!(arr, round_trip); } } diff --git a/rust/geoarrow/src/io/geos/array/mixed.rs b/rust/geoarrow/src/io/geos/array/mixed.rs index 0afcfceb..492178b0 100644 --- a/rust/geoarrow/src/io/geos/array/mixed.rs +++ b/rust/geoarrow/src/io/geos/array/mixed.rs @@ -2,7 +2,7 @@ use crate::array::{MixedGeometryArray, MixedGeometryBuilder}; use crate::error::GeoArrowError; use crate::io::geos::scalar::GEOSGeometry; -impl TryFrom> for MixedGeometryBuilder { +impl TryFrom> for MixedGeometryBuilder { type Error = GeoArrowError; fn try_from(value: Vec) -> std::result::Result { @@ -11,11 +11,11 @@ impl TryFrom> for MixedGeometryBuilder { } } -impl TryFrom> for MixedGeometryArray { +impl TryFrom> for MixedGeometryArray { type Error = GeoArrowError; fn try_from(value: Vec) -> std::result::Result { - let mutable_arr: MixedGeometryBuilder = value.try_into()?; + let mutable_arr: MixedGeometryBuilder = value.try_into()?; Ok(mutable_arr.into()) } } diff --git a/rust/geoarrow/src/io/geos/array/multilinestring.rs b/rust/geoarrow/src/io/geos/array/multilinestring.rs index 42807e37..0dda7b1c 100644 --- a/rust/geoarrow/src/io/geos/array/multilinestring.rs +++ b/rust/geoarrow/src/io/geos/array/multilinestring.rs @@ -2,7 +2,7 @@ use crate::array::{MultiLineStringArray, MultiLineStringBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSMultiLineString; -impl MultiLineStringBuilder { +impl MultiLineStringBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_objects: Vec> = value @@ -13,7 +13,7 @@ impl MultiLineStringBuilder { } } -impl MultiLineStringArray { +impl MultiLineStringArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = MultiLineStringBuilder::from_geos(value)?; Ok(mutable_arr.into()) diff --git a/rust/geoarrow/src/io/geos/array/multipoint.rs b/rust/geoarrow/src/io/geos/array/multipoint.rs index ae55055a..387e7756 100644 --- a/rust/geoarrow/src/io/geos/array/multipoint.rs +++ b/rust/geoarrow/src/io/geos/array/multipoint.rs @@ -2,7 +2,7 @@ use crate::array::{MultiPointArray, MultiPointBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSMultiPoint; -impl MultiPointBuilder { +impl MultiPointBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_objects: Vec> = value @@ -13,7 +13,7 @@ impl MultiPointBuilder { } } -impl MultiPointArray { +impl MultiPointArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = MultiPointBuilder::from_geos(value)?; Ok(mutable_arr.into()) diff --git a/rust/geoarrow/src/io/geos/array/multipolygon.rs b/rust/geoarrow/src/io/geos/array/multipolygon.rs index ff2988d7..40ed7de3 100644 --- a/rust/geoarrow/src/io/geos/array/multipolygon.rs +++ b/rust/geoarrow/src/io/geos/array/multipolygon.rs @@ -2,7 +2,7 @@ use crate::array::{MultiPolygonArray, MultiPolygonBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSMultiPolygon; -impl MultiPolygonBuilder { +impl MultiPolygonBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_objects: Vec> = value @@ -13,7 +13,7 @@ impl MultiPolygonBuilder { } } -impl MultiPolygonArray { +impl MultiPolygonArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = MultiPolygonBuilder::from_geos(value)?; Ok(mutable_arr.into()) diff --git a/rust/geoarrow/src/io/geos/array/point.rs b/rust/geoarrow/src/io/geos/array/point.rs index d0f1bf5d..f387b17d 100644 --- a/rust/geoarrow/src/io/geos/array/point.rs +++ b/rust/geoarrow/src/io/geos/array/point.rs @@ -2,7 +2,7 @@ use crate::array::{PointArray, PointBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSPoint; -impl PointBuilder { +impl PointBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_linestring_objects: Vec> = value @@ -13,7 +13,7 @@ impl PointBuilder { } } -impl PointArray { +impl PointArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = PointBuilder::from_geos(value)?; Ok(mutable_arr.into()) diff --git a/rust/geoarrow/src/io/geos/array/polygon.rs b/rust/geoarrow/src/io/geos/array/polygon.rs index 54bec8b6..aef53b04 100644 --- a/rust/geoarrow/src/io/geos/array/polygon.rs +++ b/rust/geoarrow/src/io/geos/array/polygon.rs @@ -2,7 +2,7 @@ use crate::array::{PolygonArray, PolygonBuilder}; use crate::error::Result; use crate::io::geos::scalar::GEOSPolygon; -impl PolygonBuilder { +impl PolygonBuilder { pub fn from_geos(value: Vec>) -> Result { // TODO: don't use new_unchecked let geos_objects: Vec> = value @@ -14,7 +14,7 @@ impl PolygonBuilder { } } -impl PolygonArray { +impl PolygonArray { pub fn from_geos(value: Vec>) -> Result { let mutable_arr = PolygonBuilder::from_geos(value)?; Ok(mutable_arr.into()) diff --git a/rust/geoarrow/src/io/postgis/reader.rs b/rust/geoarrow/src/io/postgis/reader.rs index 4e98ca22..53945b49 100644 --- a/rust/geoarrow/src/io/postgis/reader.rs +++ b/rust/geoarrow/src/io/postgis/reader.rs @@ -172,7 +172,7 @@ pub async fn read_postgis<'c, E: Executor<'c, Database = Postgres>>( ) -> Result> { let query = sqlx::query::(sql); let mut result_stream = query.fetch(executor); - let mut table_builder: Option>> = None; + let mut table_builder: Option> = None; // TODO: try out chunking with `result_stream.try_chunks` let mut row_idx = 0; diff --git a/rust/geoarrow/src/io/wkb/api.rs b/rust/geoarrow/src/io/wkb/api.rs index 4a3ee9c9..21c30783 100644 --- a/rust/geoarrow/src/io/wkb/api.rs +++ b/rust/geoarrow/src/io/wkb/api.rs @@ -22,7 +22,7 @@ pub trait FromWKB: Sized { fn from_wkb(arr: &Self::Input, coord_type: CoordType) -> Result; } -impl FromWKB for PointArray<2> { +impl FromWKB for PointArray { type Input = WKBArray; fn from_wkb(arr: &WKBArray, coord_type: CoordType) -> Result { @@ -49,33 +49,29 @@ macro_rules! impl_from_wkb { }; } -impl_from_wkb!(LineStringArray<2>, LineStringBuilder<2>); -impl_from_wkb!(PolygonArray<2>, PolygonBuilder<2>); -impl_from_wkb!(MultiPointArray<2>, MultiPointBuilder<2>); -impl_from_wkb!(MultiLineStringArray<2>, MultiLineStringBuilder<2>); -impl_from_wkb!(MultiPolygonArray<2>, MultiPolygonBuilder<2>); +impl_from_wkb!(LineStringArray, LineStringBuilder); +impl_from_wkb!(PolygonArray, PolygonBuilder); +impl_from_wkb!(MultiPointArray, MultiPointBuilder); +impl_from_wkb!(MultiLineStringArray, MultiLineStringBuilder); +impl_from_wkb!(MultiPolygonArray, MultiPolygonBuilder); -impl FromWKB for MixedGeometryArray<2> { +impl FromWKB for MixedGeometryArray { type Input = WKBArray; fn from_wkb(arr: &WKBArray, coord_type: CoordType) -> Result { let wkb_objects: Vec>> = arr.iter().collect(); - let builder = MixedGeometryBuilder::<2>::from_wkb( - &wkb_objects, - Some(coord_type), - arr.metadata(), - true, - )?; + let builder = + MixedGeometryBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata(), true)?; Ok(builder.finish()) } } -impl FromWKB for GeometryCollectionArray<2> { +impl FromWKB for GeometryCollectionArray { type Input = WKBArray; fn from_wkb(arr: &WKBArray, coord_type: CoordType) -> Result { let wkb_objects: Vec>> = arr.iter().collect(); - let builder = GeometryCollectionBuilder::<2>::from_wkb( + let builder = GeometryCollectionBuilder::from_wkb( &wkb_objects, Some(coord_type), arr.metadata(), @@ -90,7 +86,7 @@ impl FromWKB for Arc { fn from_wkb(arr: &WKBArray, coord_type: CoordType) -> Result { let wkb_objects: Vec>> = arr.iter().collect(); - let builder = GeometryCollectionBuilder::<2>::from_wkb( + let builder = GeometryCollectionBuilder::from_wkb( &wkb_objects, Some(coord_type), arr.metadata(), @@ -100,7 +96,7 @@ impl FromWKB for Arc { } } -impl FromWKB for ChunkedPointArray<2> { +impl FromWKB for ChunkedPointArray { type Input = ChunkedWKBArray; fn from_wkb(arr: &Self::Input, coord_type: CoordType) -> Result { @@ -125,13 +121,13 @@ macro_rules! impl_chunked { }; } -impl_chunked!(ChunkedLineStringArray<2>); -impl_chunked!(ChunkedPolygonArray<2>); -impl_chunked!(ChunkedMultiPointArray<2>); -impl_chunked!(ChunkedMultiLineStringArray<2>); -impl_chunked!(ChunkedMultiPolygonArray<2>); -impl_chunked!(ChunkedMixedGeometryArray<2>); -impl_chunked!(ChunkedGeometryCollectionArray<2>); +impl_chunked!(ChunkedLineStringArray); +impl_chunked!(ChunkedPolygonArray); +impl_chunked!(ChunkedMultiPointArray); +impl_chunked!(ChunkedMultiLineStringArray); +impl_chunked!(ChunkedMultiPolygonArray); +impl_chunked!(ChunkedMixedGeometryArray); +impl_chunked!(ChunkedGeometryCollectionArray); impl FromWKB for Arc { type Input = ChunkedWKBArray; @@ -140,7 +136,7 @@ impl FromWKB for Arc { arr: &ChunkedWKBArray, coord_type: CoordType, ) -> Result { - let geom_arr = ChunkedGeometryCollectionArray::<2>::from_wkb(arr, coord_type)?; + let geom_arr = ChunkedGeometryCollectionArray::from_wkb(arr, coord_type)?; Ok(geom_arr.downcast(true)) } } @@ -154,95 +150,44 @@ pub fn from_wkb( prefer_multi: bool, ) -> Result> { use NativeType::*; + let target_dim = target_geo_data_type.dimension(); let wkb_objects: Vec>> = arr.iter().collect(); match target_geo_data_type { - Point(coord_type, Dimension::XY) => { - let builder = - PointBuilder::<2>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - LineString(coord_type, Dimension::XY) => { - let builder = - LineStringBuilder::<2>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - Polygon(coord_type, Dimension::XY) => { - let builder = - PolygonBuilder::<2>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - MultiPoint(coord_type, Dimension::XY) => { - let builder = - MultiPointBuilder::<2>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - MultiLineString(coord_type, Dimension::XY) => { - let builder = MultiLineStringBuilder::<2>::from_wkb( - &wkb_objects, - Some(coord_type), - arr.metadata(), - )?; - Ok(Arc::new(builder.finish())) - } - MultiPolygon(coord_type, Dimension::XY) => { - let builder = - MultiPolygonBuilder::<2>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - Mixed(coord_type, Dimension::XY) => { - let builder = MixedGeometryBuilder::<2>::from_wkb( - &wkb_objects, - Some(coord_type), - arr.metadata(), - prefer_multi, - )?; + Point(coord_type, _) => { + let builder = PointBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; Ok(Arc::new(builder.finish())) } - GeometryCollection(coord_type, Dimension::XY) => { - let builder = GeometryCollectionBuilder::<2>::from_wkb( + LineString(coord_type, _) => { + let builder = LineStringBuilder::from_wkb( + target_dim, &wkb_objects, Some(coord_type), arr.metadata(), - prefer_multi, )?; Ok(Arc::new(builder.finish())) } - Point(coord_type, Dimension::XYZ) => { - let builder = - PointBuilder::<3>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; + Polygon(coord_type, _) => { + let builder = PolygonBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; Ok(Arc::new(builder.finish())) } - LineString(coord_type, Dimension::XYZ) => { + MultiPoint(coord_type, _) => { let builder = - LineStringBuilder::<3>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; + MultiPointBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; Ok(Arc::new(builder.finish())) } - Polygon(coord_type, Dimension::XYZ) => { + MultiLineString(coord_type, _) => { let builder = - PolygonBuilder::<3>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; + MultiLineStringBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; Ok(Arc::new(builder.finish())) } - MultiPoint(coord_type, Dimension::XYZ) => { + MultiPolygon(coord_type, _) => { let builder = - MultiPointBuilder::<3>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; + MultiPolygonBuilder::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; Ok(Arc::new(builder.finish())) } - MultiLineString(coord_type, Dimension::XYZ) => { - let builder = MultiLineStringBuilder::<3>::from_wkb( - &wkb_objects, - Some(coord_type), - arr.metadata(), - )?; - Ok(Arc::new(builder.finish())) - } - MultiPolygon(coord_type, Dimension::XYZ) => { - let builder = - MultiPolygonBuilder::<3>::from_wkb(&wkb_objects, Some(coord_type), arr.metadata())?; - Ok(Arc::new(builder.finish())) - } - Mixed(coord_type, Dimension::XYZ) => { - let builder = MixedGeometryBuilder::<3>::from_wkb( + Mixed(coord_type, _) => { + let builder = MixedGeometryBuilder::from_wkb( &wkb_objects, Some(coord_type), arr.metadata(), @@ -250,8 +195,8 @@ pub fn from_wkb( )?; Ok(Arc::new(builder.finish())) } - GeometryCollection(coord_type, Dimension::XYZ) => { - let builder = GeometryCollectionBuilder::<3>::from_wkb( + GeometryCollection(coord_type, _) => { + let builder = GeometryCollectionBuilder::from_wkb( &wkb_objects, Some(coord_type), arr.metadata(), @@ -281,27 +226,18 @@ impl ToWKB for &dyn NativeArray { type Output = WKBArray; fn to_wkb(&self) -> Self::Output { - use Dimension::*; use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().into(), - LineString(_, XY) => self.as_line_string::<2>().into(), - Polygon(_, XY) => self.as_polygon::<2>().into(), - MultiPoint(_, XY) => self.as_multi_point::<2>().into(), - MultiLineString(_, XY) => self.as_multi_line_string::<2>().into(), - MultiPolygon(_, XY) => self.as_multi_polygon::<2>().into(), - Mixed(_, XY) => self.as_mixed::<2>().into(), - GeometryCollection(_, XY) => self.as_geometry_collection::<2>().into(), - - Point(_, XYZ) => self.as_point::<3>().into(), - LineString(_, XYZ) => self.as_line_string::<3>().into(), - Polygon(_, XYZ) => self.as_polygon::<3>().into(), - MultiPoint(_, XYZ) => self.as_multi_point::<3>().into(), - MultiLineString(_, XYZ) => self.as_multi_line_string::<3>().into(), - MultiPolygon(_, XYZ) => self.as_multi_polygon::<3>().into(), - Mixed(_, XYZ) => self.as_mixed::<3>().into(), - GeometryCollection(_, XYZ) => self.as_geometry_collection::<3>().into(), + Point(_, _) => self.as_point().into(), + LineString(_, _) => self.as_line_string().into(), + Polygon(_, _) => self.as_polygon().into(), + MultiPoint(_, _) => self.as_multi_point().into(), + MultiLineString(_, _) => self.as_multi_line_string().into(), + MultiPolygon(_, _) => self.as_multi_polygon().into(), + Mixed(_, _) => self.as_mixed().into(), + GeometryCollection(_, _) => self.as_geometry_collection().into(), + Rect(_) => todo!(), } } @@ -314,54 +250,24 @@ impl ToWKB for &dyn ChunkedNativeArray { use NativeType::*; match self.data_type() { - Point(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_point::<2>().map(|chunk| chunk.into())) - } - LineString(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_line_string::<2>().map(|chunk| chunk.into())) - } - Polygon(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_polygon::<2>().map(|chunk| chunk.into())) - } - MultiPoint(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_multi_point::<2>().map(|chunk| chunk.into())) - } - MultiLineString(_, Dimension::XY) => ChunkedGeometryArray::new( - self.as_multi_line_string::<2>().map(|chunk| chunk.into()), - ), - MultiPolygon(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_multi_polygon::<2>().map(|chunk| chunk.into())) - } - Mixed(_, Dimension::XY) => { - ChunkedGeometryArray::new(self.as_mixed::<2>().map(|chunk| chunk.into())) - } - GeometryCollection(_, Dimension::XY) => ChunkedGeometryArray::new( - self.as_geometry_collection::<2>().map(|chunk| chunk.into()), - ), - Point(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_point::<3>().map(|chunk| chunk.into())) - } - LineString(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_line_string::<3>().map(|chunk| chunk.into())) + Point(_, _) => ChunkedGeometryArray::new(self.as_point().map(|chunk| chunk.into())), + LineString(_, _) => { + ChunkedGeometryArray::new(self.as_line_string().map(|chunk| chunk.into())) } - Polygon(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_polygon::<3>().map(|chunk| chunk.into())) + Polygon(_, _) => ChunkedGeometryArray::new(self.as_polygon().map(|chunk| chunk.into())), + MultiPoint(_, _) => { + ChunkedGeometryArray::new(self.as_multi_point().map(|chunk| chunk.into())) } - MultiPoint(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_multi_point::<3>().map(|chunk| chunk.into())) + MultiLineString(_, _) => { + ChunkedGeometryArray::new(self.as_multi_line_string().map(|chunk| chunk.into())) } - MultiLineString(_, Dimension::XYZ) => ChunkedGeometryArray::new( - self.as_multi_line_string::<3>().map(|chunk| chunk.into()), - ), - MultiPolygon(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_multi_polygon::<3>().map(|chunk| chunk.into())) + MultiPolygon(_, _) => { + ChunkedGeometryArray::new(self.as_multi_polygon().map(|chunk| chunk.into())) } - Mixed(_, Dimension::XYZ) => { - ChunkedGeometryArray::new(self.as_mixed::<3>().map(|chunk| chunk.into())) + Mixed(_, _) => ChunkedGeometryArray::new(self.as_mixed().map(|chunk| chunk.into())), + GeometryCollection(_, _) => { + ChunkedGeometryArray::new(self.as_geometry_collection().map(|chunk| chunk.into())) } - GeometryCollection(_, Dimension::XYZ) => ChunkedGeometryArray::new( - self.as_geometry_collection::<3>().map(|chunk| chunk.into()), - ), Rect(_) => todo!(), } } @@ -372,22 +278,14 @@ pub fn to_wkb(arr: &dyn NativeArray) -> WKBArray { use NativeType::*; match arr.data_type() { - Point(_, Dimension::XY) => arr.as_point::<2>().into(), - LineString(_, Dimension::XY) => arr.as_line_string::<2>().into(), - Polygon(_, Dimension::XY) => arr.as_polygon::<2>().into(), - MultiPoint(_, Dimension::XY) => arr.as_multi_point::<2>().into(), - MultiLineString(_, Dimension::XY) => arr.as_multi_line_string::<2>().into(), - MultiPolygon(_, Dimension::XY) => arr.as_multi_polygon::<2>().into(), - Mixed(_, Dimension::XY) => arr.as_mixed::<2>().into(), - GeometryCollection(_, Dimension::XY) => arr.as_geometry_collection::<2>().into(), - Point(_, Dimension::XYZ) => arr.as_point::<3>().into(), - LineString(_, Dimension::XYZ) => arr.as_line_string::<3>().into(), - Polygon(_, Dimension::XYZ) => arr.as_polygon::<3>().into(), - MultiPoint(_, Dimension::XYZ) => arr.as_multi_point::<3>().into(), - MultiLineString(_, Dimension::XYZ) => arr.as_multi_line_string::<3>().into(), - MultiPolygon(_, Dimension::XYZ) => arr.as_multi_polygon::<3>().into(), - Mixed(_, Dimension::XYZ) => arr.as_mixed::<3>().into(), - GeometryCollection(_, Dimension::XYZ) => arr.as_geometry_collection::<3>().into(), + Point(_, _) => arr.as_point().into(), + LineString(_, _) => arr.as_line_string().into(), + Polygon(_, _) => arr.as_polygon().into(), + MultiPoint(_, _) => arr.as_multi_point().into(), + MultiLineString(_, _) => arr.as_multi_line_string().into(), + MultiPolygon(_, _) => arr.as_multi_polygon().into(), + Mixed(_, _) => arr.as_mixed().into(), + GeometryCollection(_, _) => arr.as_geometry_collection().into(), Rect(_) => todo!(), } } @@ -408,7 +306,7 @@ mod test { ) .unwrap(); let rt_point_arr = roundtrip.as_ref(); - let rt_point_arr_ref = rt_point_arr.as_point::<2>(); + let rt_point_arr_ref = rt_point_arr.as_point(); assert_eq!(&arr, rt_point_arr_ref); } @@ -423,10 +321,10 @@ mod test { ) .unwrap(); let rt_ref = roundtrip.as_ref(); - let rt_mixed_arr = rt_ref.as_mixed::<2>(); + let rt_mixed_arr = rt_ref.as_mixed(); let downcasted = rt_mixed_arr.downcast(true); let downcasted_ref = downcasted.as_ref(); - let rt_point_arr = downcasted_ref.as_point::<2>(); + let rt_point_arr = downcasted_ref.as_point(); assert_eq!(&arr, rt_point_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/geometry.rs b/rust/geoarrow/src/io/wkb/writer/geometry.rs index 5b3591fa..e790531c 100644 --- a/rust/geoarrow/src/io/wkb/writer/geometry.rs +++ b/rust/geoarrow/src/io/wkb/writer/geometry.rs @@ -9,8 +9,8 @@ use crate::trait_::ArrayAccessor; use crate::ArrayBase; use std::io::Cursor; -impl From<&MixedGeometryArray> for WKBArray { - fn from(value: &MixedGeometryArray) -> Self { +impl From<&MixedGeometryArray> for WKBArray { + fn from(value: &MixedGeometryArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -50,7 +50,7 @@ mod test { #[test] fn round_trip() { - let orig_arr: MixedGeometryArray<2> = vec![ + let orig_arr: MixedGeometryArray = vec![ Some(geo::Geometry::MultiLineString(ml0())), Some(geo::Geometry::MultiLineString(ml1())), Some(geo::Geometry::Point(p0())), @@ -59,7 +59,7 @@ mod test { .try_into() .unwrap(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: MixedGeometryArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: MixedGeometryArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } @@ -67,7 +67,7 @@ mod test { #[ignore = "None not allowed in geometry array."] #[test] fn round_trip_null() { - let orig_arr: MixedGeometryArray<2> = vec![ + let orig_arr: MixedGeometryArray = vec![ Some(geo::Geometry::MultiLineString(ml0())), Some(geo::Geometry::MultiLineString(ml1())), Some(geo::Geometry::Point(p0())), @@ -77,7 +77,7 @@ mod test { .try_into() .unwrap(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: MixedGeometryArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: MixedGeometryArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/geometrycollection.rs b/rust/geoarrow/src/io/wkb/writer/geometrycollection.rs index 749e821d..603f450e 100644 --- a/rust/geoarrow/src/io/wkb/writer/geometrycollection.rs +++ b/rust/geoarrow/src/io/wkb/writer/geometrycollection.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{geometry_collection_wkb_size, write_geometry_collection}; use wkb::Endianness; -impl From<&GeometryCollectionArray> for WKBArray { - fn from(value: &GeometryCollectionArray) -> Self { +impl From<&GeometryCollectionArray> for WKBArray { + fn from(value: &GeometryCollectionArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -61,9 +61,9 @@ mod test { geo::Geometry::MultiPolygon(multipolygon::mp1()), ]); - let orig_arr: GeometryCollectionArray<2> = vec![Some(gc0), Some(gc1), None].into(); + let orig_arr: GeometryCollectionArray = vec![Some(gc0), Some(gc1), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: GeometryCollectionArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: GeometryCollectionArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/linestring.rs b/rust/geoarrow/src/io/wkb/writer/linestring.rs index eebb3a73..e9b6c515 100644 --- a/rust/geoarrow/src/io/wkb/writer/linestring.rs +++ b/rust/geoarrow/src/io/wkb/writer/linestring.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{line_string_wkb_size, write_line_string}; use wkb::Endianness; -impl From<&LineStringArray> for WKBArray { - fn from(value: &LineStringArray) -> Self { +impl From<&LineStringArray> for WKBArray { + fn from(value: &LineStringArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -48,9 +48,9 @@ mod test { #[test] fn round_trip() { - let orig_arr: LineStringArray<2> = vec![Some(ls0()), Some(ls1()), None].into(); + let orig_arr: LineStringArray = vec![Some(ls0()), Some(ls1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: LineStringArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: LineStringArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } @@ -58,9 +58,9 @@ mod test { // TODO: parsing WKBArray into LineStringArray not yet implemented #[test] fn round_trip_to_i64() { - let orig_arr: LineStringArray<2> = vec![Some(ls0()), Some(ls1()), None].into(); + let orig_arr: LineStringArray = vec![Some(ls0()), Some(ls1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: LineStringArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: LineStringArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/multilinestring.rs b/rust/geoarrow/src/io/wkb/writer/multilinestring.rs index bcb64253..e51db496 100644 --- a/rust/geoarrow/src/io/wkb/writer/multilinestring.rs +++ b/rust/geoarrow/src/io/wkb/writer/multilinestring.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{multi_line_string_wkb_size, write_multi_line_string}; use wkb::Endianness; -impl From<&MultiLineStringArray> for WKBArray { - fn from(value: &MultiLineStringArray) -> Self { +impl From<&MultiLineStringArray> for WKBArray { + fn from(value: &MultiLineStringArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -50,9 +50,9 @@ mod test { #[test] fn round_trip() { - let orig_arr: MultiLineStringArray<2> = vec![Some(ml0()), Some(ml1()), None].into(); + let orig_arr: MultiLineStringArray = vec![Some(ml0()), Some(ml1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: MultiLineStringArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: MultiLineStringArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/multipoint.rs b/rust/geoarrow/src/io/wkb/writer/multipoint.rs index 7f4f0f39..58abbff8 100644 --- a/rust/geoarrow/src/io/wkb/writer/multipoint.rs +++ b/rust/geoarrow/src/io/wkb/writer/multipoint.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{multi_point_wkb_size, write_multi_point}; use wkb::Endianness; -impl From<&MultiPointArray> for WKBArray { - fn from(value: &MultiPointArray) -> Self { +impl From<&MultiPointArray> for WKBArray { + fn from(value: &MultiPointArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -48,9 +48,9 @@ mod test { #[test] fn round_trip() { - let orig_arr: MultiPointArray<2> = vec![Some(mp0()), Some(mp1()), None].into(); + let orig_arr: MultiPointArray = vec![Some(mp0()), Some(mp1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: MultiPointArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: MultiPointArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/multipolygon.rs b/rust/geoarrow/src/io/wkb/writer/multipolygon.rs index b7969f42..12223d20 100644 --- a/rust/geoarrow/src/io/wkb/writer/multipolygon.rs +++ b/rust/geoarrow/src/io/wkb/writer/multipolygon.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{multi_polygon_wkb_size, write_multi_polygon}; use wkb::Endianness; -impl From<&MultiPolygonArray> for WKBArray { - fn from(value: &MultiPolygonArray) -> Self { +impl From<&MultiPolygonArray> for WKBArray { + fn from(value: &MultiPolygonArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -50,9 +50,9 @@ mod test { #[test] fn round_trip() { - let orig_arr: MultiPolygonArray<2> = vec![Some(mp0()), Some(mp1()), None].into(); + let orig_arr: MultiPolygonArray = vec![Some(mp0()), Some(mp1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: MultiPolygonArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: MultiPolygonArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/point.rs b/rust/geoarrow/src/io/wkb/writer/point.rs index 7bc1c312..e3bcabe1 100644 --- a/rust/geoarrow/src/io/wkb/writer/point.rs +++ b/rust/geoarrow/src/io/wkb/writer/point.rs @@ -8,15 +8,17 @@ use std::io::Cursor; use wkb::writer::{point_wkb_size, write_point}; use wkb::Endianness; -impl From<&PointArray> for WKBArray { - fn from(value: &PointArray) -> Self { +impl From<&PointArray> for WKBArray { + fn from(value: &PointArray) -> Self { + let dim = value.coords.dim(); + let non_null_count = value .nulls() .map_or(value.len(), |validity| value.len() - validity.null_count()); let validity = value.nulls().cloned(); // only allocate space for a WKBPoint for non-null items - let values_len = non_null_count * point_wkb_size(geo_traits::Dimensions::Unknown(D)); + let values_len = non_null_count * point_wkb_size(dim.into()); let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); let values = { @@ -26,9 +28,7 @@ impl From<&PointArray> for WKBArray { for maybe_geom in value.iter() { if let Some(geom) = maybe_geom { write_point(&mut writer, &geom, Endianness::LittleEndian).unwrap(); - offsets - .try_push_usize(point_wkb_size(geo_traits::Dimensions::Unknown(D))) - .unwrap(); + offsets.try_push_usize(point_wkb_size(dim.into())).unwrap(); } else { offsets.extend_constant(1); } @@ -51,18 +51,18 @@ mod test { #[test] fn round_trip() { // TODO: test with nulls - let orig_arr: PointArray<2> = vec![Some(p0()), Some(p1()), Some(p2())].into(); + let orig_arr: PointArray = vec![Some(p0()), Some(p1()), Some(p2())].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: PointArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: PointArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } #[test] fn round_trip_with_null() { - let orig_arr: PointArray<2> = vec![Some(p0()), None, Some(p1()), None, Some(p2())].into(); + let orig_arr: PointArray = vec![Some(p0()), None, Some(p1()), None, Some(p2())].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: PointArray<2> = wkb_arr.try_into().unwrap(); + let new_arr: PointArray = wkb_arr.try_into().unwrap(); assert_eq!(orig_arr, new_arr); } diff --git a/rust/geoarrow/src/io/wkb/writer/polygon.rs b/rust/geoarrow/src/io/wkb/writer/polygon.rs index ae4d6a56..10a44b0e 100644 --- a/rust/geoarrow/src/io/wkb/writer/polygon.rs +++ b/rust/geoarrow/src/io/wkb/writer/polygon.rs @@ -8,8 +8,8 @@ use std::io::Cursor; use wkb::writer::{polygon_wkb_size, write_polygon}; use wkb::Endianness; -impl From<&PolygonArray> for WKBArray { - fn from(value: &PolygonArray) -> Self { +impl From<&PolygonArray> for WKBArray { + fn from(value: &PolygonArray) -> Self { let mut offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(value.len()); // First pass: calculate binary array offsets @@ -50,9 +50,9 @@ mod test { #[test] fn round_trip() { - let orig_arr: PolygonArray<2> = vec![Some(p0()), Some(p1()), None].into(); + let orig_arr: PolygonArray = vec![Some(p0()), Some(p1()), None].into(); let wkb_arr: WKBArray = (&orig_arr).into(); - let new_arr: PolygonArray<2> = wkb_arr.clone().try_into().unwrap(); + let new_arr: PolygonArray = wkb_arr.clone().try_into().unwrap(); let wkb0 = geo::Geometry::Polygon(p0()) .to_wkb(CoordDimensions::xy()) diff --git a/rust/geoarrow/src/io/wkt/reader/mod.rs b/rust/geoarrow/src/io/wkt/reader/mod.rs index e0437efc..aea8dcaa 100644 --- a/rust/geoarrow/src/io/wkt/reader/mod.rs +++ b/rust/geoarrow/src/io/wkt/reader/mod.rs @@ -21,7 +21,7 @@ impl ParseWKT for GenericStringArray { fn parse_wkt(&self, coord_type: CoordType, metadata: Arc) -> Self::Output { // TODO: switch this prefer_multi to true when we use downcasting here. - let mut builder = MixedGeometryBuilder::<2>::new_with_options(coord_type, metadata, false); + let mut builder = MixedGeometryBuilder::new_with_options(coord_type, metadata, false); for i in 0..self.len() { if self.is_valid(i) { let w = wkt::Wkt::::from_str(self.value(i)).unwrap(); diff --git a/rust/geoarrow/src/scalar/geometrycollection/owned.rs b/rust/geoarrow/src/scalar/geometrycollection/owned.rs index dc747eca..09408e8a 100644 --- a/rust/geoarrow/src/scalar/geometrycollection/owned.rs +++ b/rust/geoarrow/src/scalar/geometrycollection/owned.rs @@ -60,7 +60,7 @@ impl GeometryCollectionTrait for OwnedGeometryCollection { type GeometryType<'b> = Geometry<'b> where Self: 'b; fn dim(&self) -> geo_traits::Dimensions { - match self.coords.dim() { + match self.array.dim() { Dimension::XY => geo_traits::Dimensions::Xy, Dimension::XYZ => geo_traits::Dimensions::Xyz, } diff --git a/rust/geoarrow/src/test/geoarrow_data/mod.rs b/rust/geoarrow/src/test/geoarrow_data/mod.rs index 68b8b273..b73cac74 100644 --- a/rust/geoarrow/src/test/geoarrow_data/mod.rs +++ b/rust/geoarrow/src/test/geoarrow_data/mod.rs @@ -1,6 +1,7 @@ pub mod util; use crate::array::*; +use crate::datatypes::Dimension; use crate::test::geoarrow_data::util::read_geometry_column; macro_rules! geoarrow_data_impl { @@ -11,65 +12,55 @@ macro_rules! geoarrow_data_impl { $file_part ); let geometry_dyn_column = read_geometry_column(&path); - geometry_dyn_column.as_ref().try_into().unwrap() + (geometry_dyn_column.as_ref(), Dimension::XY) + .try_into() + .unwrap() } }; } // Point -geoarrow_data_impl!( - example_point_interleaved, - "point-interleaved", - PointArray<2> -); -geoarrow_data_impl!(example_point_separated, "point", PointArray<2>); +geoarrow_data_impl!(example_point_interleaved, "point-interleaved", PointArray); +geoarrow_data_impl!(example_point_separated, "point", PointArray); geoarrow_data_impl!(example_point_wkb, "point-wkb", WKBArray); // LineString geoarrow_data_impl!( example_linestring_interleaved, "linestring-interleaved", - LineStringArray<2> -); -geoarrow_data_impl!( - example_linestring_separated, - "linestring", - LineStringArray<2> + LineStringArray ); +geoarrow_data_impl!(example_linestring_separated, "linestring", LineStringArray); geoarrow_data_impl!(example_linestring_wkb, "linestring-wkb", WKBArray); // Polygon geoarrow_data_impl!( example_polygon_interleaved, "polygon-interleaved", - PolygonArray<2> + PolygonArray ); -geoarrow_data_impl!(example_polygon_separated, "polygon", PolygonArray<2>); +geoarrow_data_impl!(example_polygon_separated, "polygon", PolygonArray); geoarrow_data_impl!(example_polygon_wkb, "polygon-wkb", WKBArray); // MultiPoint geoarrow_data_impl!( example_multipoint_interleaved, "multipoint-interleaved", - MultiPointArray<2> -); -geoarrow_data_impl!( - example_multipoint_separated, - "multipoint", - MultiPointArray<2> + MultiPointArray ); +geoarrow_data_impl!(example_multipoint_separated, "multipoint", MultiPointArray); geoarrow_data_impl!(example_multipoint_wkb, "multipoint-wkb", WKBArray); // MultiLineString geoarrow_data_impl!( example_multilinestring_interleaved, "multilinestring-interleaved", - MultiLineStringArray<2> + MultiLineStringArray ); geoarrow_data_impl!( example_multilinestring_separated, "multilinestring", - MultiLineStringArray<2> + MultiLineStringArray ); geoarrow_data_impl!( example_multilinestring_wkb, @@ -81,11 +72,11 @@ geoarrow_data_impl!( geoarrow_data_impl!( example_multipolygon_interleaved, "multipolygon-interleaved", - MultiPolygonArray<2> + MultiPolygonArray ); geoarrow_data_impl!( example_multipolygon_separated, "multipolygon", - MultiPolygonArray<2> + MultiPolygonArray ); geoarrow_data_impl!(example_multipolygon_wkb, "multipolygon-wkb", WKBArray); diff --git a/rust/geoarrow/src/test/linestring.rs b/rust/geoarrow/src/test/linestring.rs index 18021f49..d277d658 100644 --- a/rust/geoarrow/src/test/linestring.rs +++ b/rust/geoarrow/src/test/linestring.rs @@ -1,6 +1,7 @@ use geo::{line_string, LineString}; -use crate::array::LineStringArray; +use crate::array::{LineStringArray, LineStringBuilder}; +use crate::datatypes::Dimension; pub(crate) fn ls0() -> LineString { line_string![ @@ -17,10 +18,13 @@ pub(crate) fn ls1() -> LineString { } #[allow(dead_code)] -pub(crate) fn ls_array() -> LineStringArray<2> { - vec![ls0(), ls1()].as_slice().into() -} - -pub(crate) fn large_ls_array() -> LineStringArray<2> { - vec![ls0(), ls1()].as_slice().into() +pub(crate) fn ls_array() -> LineStringArray { + let geoms = vec![ls0(), ls1()]; + LineStringBuilder::from_line_strings( + &geoms, + Dimension::XY, + Default::default(), + Default::default(), + ) + .finish() } diff --git a/rust/geoarrow/src/test/multilinestring.rs b/rust/geoarrow/src/test/multilinestring.rs index 88f813a5..af0b8478 100644 --- a/rust/geoarrow/src/test/multilinestring.rs +++ b/rust/geoarrow/src/test/multilinestring.rs @@ -1,6 +1,7 @@ use geo::{line_string, MultiLineString}; -use crate::array::MultiLineStringArray; +use crate::array::{MultiLineStringArray, MultiLineStringBuilder}; +use crate::datatypes::Dimension; pub(crate) fn ml0() -> MultiLineString { MultiLineString::new(vec![line_string![ @@ -28,6 +29,13 @@ pub(crate) fn ml1() -> MultiLineString { ]) } -pub(crate) fn ml_array() -> MultiLineStringArray<2> { - vec![ml0(), ml1()].as_slice().into() +pub(crate) fn ml_array() -> MultiLineStringArray { + let geoms = vec![ml0(), ml1()]; + MultiLineStringBuilder::from_multi_line_strings( + &geoms, + Dimension::XY, + Default::default(), + Default::default(), + ) + .finish() } diff --git a/rust/geoarrow/src/test/multipoint.rs b/rust/geoarrow/src/test/multipoint.rs index ce544477..45e44747 100644 --- a/rust/geoarrow/src/test/multipoint.rs +++ b/rust/geoarrow/src/test/multipoint.rs @@ -1,6 +1,6 @@ use geo::{point, MultiPoint}; -use crate::array::MultiPointArray; +use crate::array::{MultiPointArray, MultiPointBuilder}; pub(crate) fn mp0() -> MultiPoint { MultiPoint::new(vec![ @@ -24,6 +24,7 @@ pub(crate) fn mp1() -> MultiPoint { ]) } -pub(crate) fn mp_array() -> MultiPointArray<2> { - vec![mp0(), mp1()].as_slice().into() +pub(crate) fn mp_array() -> MultiPointArray { + let geoms = vec![mp0(), mp1()]; + MultiPointBuilder::from_multi_points(&geoms, Default::default(), Default::default()).finish() } diff --git a/rust/geoarrow/src/test/multipolygon.rs b/rust/geoarrow/src/test/multipolygon.rs index b4d6a9d2..04c7c113 100644 --- a/rust/geoarrow/src/test/multipolygon.rs +++ b/rust/geoarrow/src/test/multipolygon.rs @@ -46,6 +46,6 @@ pub(crate) fn mp1() -> MultiPolygon { ]) } -pub(crate) fn mp_array() -> MultiPolygonArray<2> { +pub(crate) fn mp_array() -> MultiPolygonArray { vec![mp0(), mp1()].as_slice().into() } diff --git a/rust/geoarrow/src/test/point.rs b/rust/geoarrow/src/test/point.rs index 39e58e3e..e6070ca1 100644 --- a/rust/geoarrow/src/test/point.rs +++ b/rust/geoarrow/src/test/point.rs @@ -29,8 +29,9 @@ pub(crate) fn p2() -> Point { ) } -pub(crate) fn point_array() -> PointArray<2> { - vec![p0(), p1(), p2()].as_slice().into() +pub(crate) fn point_array() -> PointArray { + let geoms = vec![p0(), p1(), p2()]; + PointBuilder::from_points(geoms.iter(), Default::default(), Default::default()).finish() } struct CoordZ { @@ -64,7 +65,7 @@ impl CoordTrait for CoordZ { } } -pub(crate) fn point_z_array() -> PointArray<3> { +pub(crate) fn point_z_array() -> PointArray { let mut builder = PointBuilder::with_capacity(3); let coords = vec![ CoordZ { diff --git a/rust/geoarrow/src/test/polygon.rs b/rust/geoarrow/src/test/polygon.rs index 2b7f22cf..95c23865 100644 --- a/rust/geoarrow/src/test/polygon.rs +++ b/rust/geoarrow/src/test/polygon.rs @@ -1,4 +1,4 @@ -use crate::array::PolygonArray; +use crate::array::{PolygonArray, PolygonBuilder}; use geo::{polygon, Polygon}; pub(crate) fn p0() -> Polygon { @@ -29,6 +29,7 @@ pub(crate) fn p1() -> Polygon { ) } -pub(crate) fn p_array() -> PolygonArray<2> { - vec![p0(), p1()].as_slice().into() +pub(crate) fn p_array() -> PolygonArray { + let geoms = vec![p0(), p1()]; + PolygonBuilder::from_polygons(&geoms, Default::default(), Default::default()).finish() } diff --git a/rust/geoarrow/src/trait_.rs b/rust/geoarrow/src/trait_.rs index 5b86ccf9..469209f1 100644 --- a/rust/geoarrow/src/trait_.rs +++ b/rust/geoarrow/src/trait_.rs @@ -2,7 +2,7 @@ use crate::array::metadata::ArrayMetadata; use crate::array::{CoordBuffer, CoordType}; -use crate::datatypes::{NativeType, SerializedType}; +use crate::datatypes::{Dimension, NativeType, SerializedType}; use crate::error::Result; use crate::scalar::Geometry; use arrow_array::{Array, ArrayRef}; @@ -857,7 +857,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; /// let builder = PointBuilder::new(Dimension::XY); /// ``` - fn new() -> Self; + fn new(dim: Dimension) -> Self; /// Creates a new builder with capacity and other options. /// @@ -879,6 +879,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// ); /// ``` fn with_geom_capacity_and_options( + dim: Dimension, geom_capacity: usize, coord_type: CoordType, metadata: Arc, @@ -895,8 +896,9 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// }; /// let builder = PointBuilder::<2>::with_geom_capacity(2); /// ``` - fn with_geom_capacity(geom_capacity: usize) -> Self { + fn with_geom_capacity(dim: Dimension, geom_capacity: usize) -> Self { GeometryArrayBuilder::with_geom_capacity_and_options( + dim, geom_capacity, Default::default(), Default::default(),