diff --git a/python/geoarrow-core/src/constructors.rs b/python/geoarrow-core/src/constructors.rs index e5e7e20e..7abe2ec3 100644 --- a/python/geoarrow-core/src/constructors.rs +++ b/python/geoarrow-core/src/constructors.rs @@ -22,7 +22,7 @@ fn create_array_metadata(crs: Option) -> Arc { pub fn points(coords: PyCoordBuffer, crs: Option) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); // TODO: remove const generic - let array = PointArray::<2>::new(coords.into_inner(), None, metadata); + let array = PointArray::new(coords.into_inner(), None, metadata); Ok(PyNativeArray::new(NativeArrayDyn::new(Arc::new(array)))) } @@ -35,7 +35,7 @@ pub fn linestrings( ) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); // TODO: remove const generic - let array = LineStringArray::<2>::new( + let array = LineStringArray::new( coords.into_inner(), geom_offsets.into_inner(), None, @@ -54,7 +54,7 @@ pub fn polygons( ) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); // TODO: remove const generic - let array = PolygonArray::<2>::new( + let array = PolygonArray::new( coords.into_inner(), geom_offsets.into_inner(), ring_offsets.into_inner(), @@ -72,7 +72,7 @@ pub fn multipoints( crs: Option, ) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); - let array = MultiPointArray::<2>::new( + let array = MultiPointArray::new( coords.into_inner(), geom_offsets.into_inner(), None, @@ -90,7 +90,7 @@ pub fn multilinestrings( crs: Option, ) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); - let array = MultiLineStringArray::<2>::new( + let array = MultiLineStringArray::new( coords.into_inner(), geom_offsets.into_inner(), ring_offsets.into_inner(), @@ -110,7 +110,7 @@ pub fn multipolygons( crs: Option, ) -> PyGeoArrowResult { let metadata = create_array_metadata(crs); - let array = MultiPolygonArray::<2>::new( + let array = MultiPolygonArray::new( coords.into_inner(), geom_offsets.into_inner(), polygon_offsets.into_inner(), diff --git a/rust/geoarrow/src/algorithm/native/concatenate.rs b/rust/geoarrow/src/algorithm/native/concatenate.rs index 6b6162cd..50507875 100644 --- a/rust/geoarrow/src/algorithm/native/concatenate.rs +++ b/rust/geoarrow/src/algorithm/native/concatenate.rs @@ -9,8 +9,8 @@ pub trait Concatenate: Sized { fn concatenate(&self) -> Self::Output; } -impl Concatenate for &[PointArray<2>] { - type Output = Result>; +impl Concatenate for &[PointArray] { + type Output = Result; fn concatenate(&self) -> Self::Output { let output_capacity = self.iter().fold(0, |sum, val| sum + val.buffer_lengths()); @@ -43,50 +43,45 @@ macro_rules! impl_concatenate { } impl_concatenate!( - LineStringArray<2>, + LineStringArray, LineStringCapacity, - LineStringBuilder<2>, + LineStringBuilder, push_line_string ); +impl_concatenate!(PolygonArray, PolygonCapacity, PolygonBuilder, push_polygon); impl_concatenate!( - PolygonArray<2>, - PolygonCapacity, - PolygonBuilder<2>, - push_polygon -); -impl_concatenate!( - MultiPointArray<2>, + MultiPointArray, MultiPointCapacity, - MultiPointBuilder<2>, + MultiPointBuilder, push_multi_point ); impl_concatenate!( - MultiLineStringArray<2>, + MultiLineStringArray, MultiLineStringCapacity, - MultiLineStringBuilder<2>, + MultiLineStringBuilder, push_multi_line_string ); impl_concatenate!( - MultiPolygonArray<2>, + MultiPolygonArray, MultiPolygonCapacity, - MultiPolygonBuilder<2>, + MultiPolygonBuilder, push_multi_polygon ); impl_concatenate!( - MixedGeometryArray<2>, + MixedGeometryArray, MixedCapacity, - MixedGeometryBuilder<2>, + MixedGeometryBuilder, push_geometry ); impl_concatenate!( - GeometryCollectionArray<2>, + GeometryCollectionArray, GeometryCollectionCapacity, - GeometryCollectionBuilder<2>, + GeometryCollectionBuilder, push_geometry_collection ); -impl Concatenate for ChunkedPointArray<2> { - type Output = Result>; +impl Concatenate for ChunkedPointArray { + type Output = Result; fn concatenate(&self) -> Self::Output { self.chunks.as_slice().concatenate() @@ -105,13 +100,10 @@ macro_rules! impl_chunked_concatenate { }; } -impl_chunked_concatenate!(ChunkedLineStringArray<2>, LineStringArray<2>); -impl_chunked_concatenate!(ChunkedPolygonArray<2>, PolygonArray<2>); -impl_chunked_concatenate!(ChunkedMultiPointArray<2>, MultiPointArray<2>); -impl_chunked_concatenate!(ChunkedMultiLineStringArray<2>, MultiLineStringArray<2>); -impl_chunked_concatenate!(ChunkedMultiPolygonArray<2>, MultiPolygonArray<2>); -impl_chunked_concatenate!(ChunkedMixedGeometryArray<2>, MixedGeometryArray<2>); -impl_chunked_concatenate!( - ChunkedGeometryCollectionArray<2>, - GeometryCollectionArray<2> -); +impl_chunked_concatenate!(ChunkedLineStringArray, LineStringArray); +impl_chunked_concatenate!(ChunkedPolygonArray, PolygonArray); +impl_chunked_concatenate!(ChunkedMultiPointArray, MultiPointArray); +impl_chunked_concatenate!(ChunkedMultiLineStringArray, MultiLineStringArray); +impl_chunked_concatenate!(ChunkedMultiPolygonArray, MultiPolygonArray); +impl_chunked_concatenate!(ChunkedMixedGeometryArray, MixedGeometryArray); +impl_chunked_concatenate!(ChunkedGeometryCollectionArray, GeometryCollectionArray); diff --git a/rust/geoarrow/src/algorithm/native/downcast.rs b/rust/geoarrow/src/algorithm/native/downcast.rs index bdf306bb..9006f37e 100644 --- a/rust/geoarrow/src/algorithm/native/downcast.rs +++ b/rust/geoarrow/src/algorithm/native/downcast.rs @@ -38,7 +38,7 @@ pub trait Downcast { fn downcast(&self, small_offsets: bool) -> Self::Output; } -impl Downcast for PointArray<2> { +impl Downcast for PointArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -90,7 +90,7 @@ pub(crate) fn can_downcast_multi(buffer: &OffsetBuffer) - .all(|slice| *slice.get(1).unwrap() - *slice.first().unwrap() <= O::one()) } -impl Downcast for LineStringArray<2> { +impl Downcast for LineStringArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -111,7 +111,7 @@ impl Downcast for LineStringArray<2> { } } -impl Downcast for PolygonArray<2> { +impl Downcast for PolygonArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -126,7 +126,7 @@ impl Downcast for PolygonArray<2> { } } -impl Downcast for MultiPointArray<2> { +impl Downcast for MultiPointArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -144,7 +144,7 @@ impl Downcast for MultiPointArray<2> { fn downcast(&self, small_offsets: bool) -> Self::Output { // Note: this won't allow a downcast for empty MultiPoints if *self.geom_offsets.last() as usize == self.len() { - return Arc::new(PointArray::<2>::new( + return Arc::new(PointArray::new( self.coords.clone(), self.validity.clone(), self.metadata(), @@ -155,7 +155,7 @@ impl Downcast for MultiPointArray<2> { } } -impl Downcast for MultiLineStringArray<2> { +impl Downcast for MultiLineStringArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -173,7 +173,7 @@ impl Downcast for MultiLineStringArray<2> { fn downcast(&self, small_offsets: bool) -> Self::Output { if *self.geom_offsets.last() as usize == self.len() { - return Arc::new(LineStringArray::<2>::new( + return Arc::new(LineStringArray::new( self.coords.clone(), self.ring_offsets.clone(), self.validity.clone(), @@ -185,7 +185,7 @@ impl Downcast for MultiLineStringArray<2> { } } -impl Downcast for MultiPolygonArray<2> { +impl Downcast for MultiPolygonArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -203,7 +203,7 @@ impl Downcast for MultiPolygonArray<2> { fn downcast(&self, small_offsets: bool) -> Self::Output { if *self.geom_offsets.last() as usize == self.len() { - return Arc::new(PolygonArray::<2>::new( + return Arc::new(PolygonArray::new( self.coords.clone(), self.polygon_offsets.clone(), self.ring_offsets.clone(), @@ -216,7 +216,7 @@ impl Downcast for MultiPolygonArray<2> { } } -impl Downcast for MixedGeometryArray<2> { +impl Downcast for MixedGeometryArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -351,7 +351,7 @@ impl Downcast for MixedGeometryArray<2> { } } -impl Downcast for GeometryCollectionArray<2> { +impl Downcast for GeometryCollectionArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -368,7 +368,7 @@ impl Downcast for GeometryCollectionArray<2> { } } -impl Downcast for RectArray<2> { +impl Downcast for RectArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -387,25 +387,19 @@ impl Downcast for &dyn NativeArray { use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().downcasted_data_type(small_offsets), - LineString(_, XY) => self - .as_line_string::<2>() - .downcasted_data_type(small_offsets), - Polygon(_, XY) => self.as_polygon::<2>().downcasted_data_type(small_offsets), - MultiPoint(_, XY) => self - .as_multi_point::<2>() - .downcasted_data_type(small_offsets), + Point(_, XY) => self.as_point().downcasted_data_type(small_offsets), + LineString(_, XY) => self.as_line_string().downcasted_data_type(small_offsets), + Polygon(_, XY) => self.as_polygon().downcasted_data_type(small_offsets), + MultiPoint(_, XY) => self.as_multi_point().downcasted_data_type(small_offsets), MultiLineString(_, XY) => self - .as_multi_line_string::<2>() - .downcasted_data_type(small_offsets), - MultiPolygon(_, XY) => self - .as_multi_polygon::<2>() + .as_multi_line_string() .downcasted_data_type(small_offsets), - Mixed(_, XY) => self.as_mixed::<2>().downcasted_data_type(small_offsets), + MultiPolygon(_, XY) => self.as_multi_polygon().downcasted_data_type(small_offsets), + Mixed(_, XY) => self.as_mixed().downcasted_data_type(small_offsets), GeometryCollection(_, XY) => self - .as_geometry_collection::<2>() + .as_geometry_collection() .downcasted_data_type(small_offsets), - Rect(XY) => self.as_rect::<2>().downcasted_data_type(small_offsets), + Rect(XY) => self.as_rect().downcasted_data_type(small_offsets), _ => todo!("3d support"), } } @@ -415,15 +409,15 @@ impl Downcast for &dyn NativeArray { use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().downcast(small_offsets), - LineString(_, XY) => self.as_line_string::<2>().downcast(small_offsets), - Polygon(_, XY) => self.as_polygon::<2>().downcast(small_offsets), - MultiPoint(_, XY) => self.as_multi_point::<2>().downcast(small_offsets), - MultiLineString(_, XY) => self.as_multi_line_string::<2>().downcast(small_offsets), - MultiPolygon(_, XY) => self.as_multi_polygon::<2>().downcast(small_offsets), - Mixed(_, XY) => self.as_mixed::<2>().downcast(small_offsets), - GeometryCollection(_, XY) => self.as_geometry_collection::<2>().downcast(small_offsets), - Rect(XY) => self.as_rect::<2>().downcast(small_offsets), + Point(_, XY) => self.as_point().downcast(small_offsets), + LineString(_, XY) => self.as_line_string().downcast(small_offsets), + Polygon(_, XY) => self.as_polygon().downcast(small_offsets), + MultiPoint(_, XY) => self.as_multi_point().downcast(small_offsets), + MultiLineString(_, XY) => self.as_multi_line_string().downcast(small_offsets), + MultiPolygon(_, XY) => self.as_multi_polygon().downcast(small_offsets), + Mixed(_, XY) => self.as_mixed().downcast(small_offsets), + GeometryCollection(_, XY) => self.as_geometry_collection().downcast(small_offsets), + Rect(XY) => self.as_rect().downcast(small_offsets), _ => todo!("3d support"), } } @@ -463,7 +457,7 @@ fn resolve_types(types: &HashSet) -> NativeType { } } -impl Downcast for ChunkedPointArray<2> { +impl Downcast for ChunkedPointArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -499,15 +493,15 @@ macro_rules! impl_chunked_downcast { }; } -impl_chunked_downcast!(ChunkedLineStringArray<2>); -impl_chunked_downcast!(ChunkedPolygonArray<2>); -impl_chunked_downcast!(ChunkedMultiPointArray<2>); -impl_chunked_downcast!(ChunkedMultiLineStringArray<2>); -impl_chunked_downcast!(ChunkedMultiPolygonArray<2>); -impl_chunked_downcast!(ChunkedMixedGeometryArray<2>); -impl_chunked_downcast!(ChunkedGeometryCollectionArray<2>); +impl_chunked_downcast!(ChunkedLineStringArray); +impl_chunked_downcast!(ChunkedPolygonArray); +impl_chunked_downcast!(ChunkedMultiPointArray); +impl_chunked_downcast!(ChunkedMultiLineStringArray); +impl_chunked_downcast!(ChunkedMultiPolygonArray); +impl_chunked_downcast!(ChunkedMixedGeometryArray); +impl_chunked_downcast!(ChunkedGeometryCollectionArray); -impl Downcast for ChunkedRectArray<2> { +impl Downcast for ChunkedRectArray { type Output = Arc; fn downcasted_data_type(&self, small_offsets: bool) -> NativeType { @@ -526,25 +520,19 @@ impl Downcast for &dyn ChunkedNativeArray { use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().downcasted_data_type(small_offsets), - LineString(_, XY) => self - .as_line_string::<2>() - .downcasted_data_type(small_offsets), - Polygon(_, XY) => self.as_polygon::<2>().downcasted_data_type(small_offsets), - MultiPoint(_, XY) => self - .as_multi_point::<2>() - .downcasted_data_type(small_offsets), + Point(_, XY) => self.as_point().downcasted_data_type(small_offsets), + LineString(_, XY) => self.as_line_string().downcasted_data_type(small_offsets), + Polygon(_, XY) => self.as_polygon().downcasted_data_type(small_offsets), + MultiPoint(_, XY) => self.as_multi_point().downcasted_data_type(small_offsets), MultiLineString(_, XY) => self - .as_multi_line_string::<2>() - .downcasted_data_type(small_offsets), - MultiPolygon(_, XY) => self - .as_multi_polygon::<2>() + .as_multi_line_string() .downcasted_data_type(small_offsets), - Mixed(_, XY) => self.as_mixed::<2>().downcasted_data_type(small_offsets), + MultiPolygon(_, XY) => self.as_multi_polygon().downcasted_data_type(small_offsets), + Mixed(_, XY) => self.as_mixed().downcasted_data_type(small_offsets), GeometryCollection(_, XY) => self - .as_geometry_collection::<2>() + .as_geometry_collection() .downcasted_data_type(small_offsets), - Rect(XY) => self.as_rect::<2>().downcasted_data_type(small_offsets), + Rect(XY) => self.as_rect().downcasted_data_type(small_offsets), _ => todo!("3d support"), } } @@ -554,15 +542,15 @@ impl Downcast for &dyn ChunkedNativeArray { use NativeType::*; match self.data_type() { - Point(_, XY) => self.as_point::<2>().downcast(small_offsets), - LineString(_, XY) => self.as_line_string::<2>().downcast(small_offsets), - Polygon(_, XY) => self.as_polygon::<2>().downcast(small_offsets), - MultiPoint(_, XY) => self.as_multi_point::<2>().downcast(small_offsets), - MultiLineString(_, XY) => self.as_multi_line_string::<2>().downcast(small_offsets), - MultiPolygon(_, XY) => self.as_multi_polygon::<2>().downcast(small_offsets), - Mixed(_, XY) => self.as_mixed::<2>().downcast(small_offsets), - GeometryCollection(_, XY) => self.as_geometry_collection::<2>().downcast(small_offsets), - Rect(XY) => self.as_rect::<2>().downcast(small_offsets), + Point(_, XY) => self.as_point().downcast(small_offsets), + LineString(_, XY) => self.as_line_string().downcast(small_offsets), + Polygon(_, XY) => self.as_polygon().downcast(small_offsets), + MultiPoint(_, XY) => self.as_multi_point().downcast(small_offsets), + MultiLineString(_, XY) => self.as_multi_line_string().downcast(small_offsets), + MultiPolygon(_, XY) => self.as_multi_polygon().downcast(small_offsets), + Mixed(_, XY) => self.as_mixed().downcast(small_offsets), + GeometryCollection(_, XY) => self.as_geometry_collection().downcast(small_offsets), + Rect(XY) => self.as_rect().downcast(small_offsets), _ => todo!("3d support"), } } @@ -611,7 +599,7 @@ impl DowncastTable for Table { } } -// impl Downcast for ChunkedMultiPointArray<2> { +// impl Downcast for ChunkedMultiPointArray { // type Output = Arc; // fn downcast(&self) -> Self::Output { diff --git a/rust/geoarrow/src/array/linestring/array.rs b/rust/geoarrow/src/array/linestring/array.rs index d969cd46..11a1a69b 100644 --- a/rust/geoarrow/src/array/linestring/array.rs +++ b/rust/geoarrow/src/array/linestring/array.rs @@ -10,7 +10,7 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, MultiLineStringArray, MultiPointArray, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, LineString}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -346,11 +346,11 @@ impl IntoArrow for LineStringArray { } } -impl TryFrom<&GenericListArray> for LineStringArray { +impl TryFrom<(&GenericListArray, Dimension)> for LineStringArray { type Error = GeoArrowError; - fn try_from(value: &GenericListArray) -> Result { - let coords = CoordBuffer::from_arrow(value.values().as_ref(), D.try_into()?)?; + fn try_from((value, dim): (&GenericListArray, Dimension)) -> Result { + let coords = CoordBuffer::from_arrow(value.values().as_ref(), dim)?; let geom_offsets = value.offsets(); let validity = value.nulls(); @@ -363,11 +363,11 @@ impl TryFrom<&GenericListArray> for LineStringArray { } } -impl TryFrom<&GenericListArray> for LineStringArray { +impl TryFrom<(&GenericListArray, Dimension)> for LineStringArray { type Error = GeoArrowError; - fn try_from(value: &GenericListArray) -> Result { - let coords = CoordBuffer::from_arrow(value.values().as_ref(), D.try_into()?)?; + fn try_from((value, dim): (&GenericListArray, Dimension)) -> Result { + let coords = CoordBuffer::from_arrow(value.values().as_ref(), dim)?; let geom_offsets = offsets_buffer_i64_to_i32(value.offsets())?; let validity = value.nulls(); @@ -379,18 +379,18 @@ impl TryFrom<&GenericListArray> for LineStringArray { )) } } -impl TryFrom<&dyn Array> for LineStringArray { +impl TryFrom<(&dyn Array, Dimension)> for LineStringArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::List(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } DataType::LargeList(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } _ => Err(GeoArrowError::General(format!( "Unexpected type: {:?}", @@ -404,7 +404,8 @@ impl TryFrom<(&dyn Array, &Field)> for LineStringArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } diff --git a/rust/geoarrow/src/array/multilinestring/array.rs b/rust/geoarrow/src/array/multilinestring/array.rs index ce2c54c5..2eb5064d 100644 --- a/rust/geoarrow/src/array/multilinestring/array.rs +++ b/rust/geoarrow/src/array/multilinestring/array.rs @@ -8,7 +8,7 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, LineStringArray, MixedGeometryArray, PolygonArray, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiLineString}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -386,10 +386,10 @@ impl IntoArrow for MultiLineStringArray { } } -impl TryFrom<&GenericListArray> for MultiLineStringArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiLineStringArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = geom_array.offsets(); let validity = geom_array.nulls(); @@ -397,7 +397,7 @@ impl TryFrom<&GenericListArray> for MultiLineStringArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = rings_array.offsets(); - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -409,10 +409,10 @@ impl TryFrom<&GenericListArray> for MultiLineStringArray { } } -impl TryFrom<&GenericListArray> for MultiLineStringArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiLineStringArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = offsets_buffer_i64_to_i32(geom_array.offsets())?; let validity = geom_array.nulls(); @@ -420,7 +420,7 @@ impl TryFrom<&GenericListArray> for MultiLineStringArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = offsets_buffer_i64_to_i32(rings_array.offsets())?; - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -432,18 +432,18 @@ impl TryFrom<&GenericListArray> for MultiLineStringArray { } } -impl TryFrom<&dyn Array> for MultiLineStringArray { +impl TryFrom<(&dyn Array, Dimension)> for MultiLineStringArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::List(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } DataType::LargeList(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } _ => Err(GeoArrowError::General(format!( "Unexpected type: {:?}", @@ -457,22 +457,21 @@ impl TryFrom<(&dyn Array, &Field)> for MultiLineStringArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } } -impl, const D: usize> From>> - for MultiLineStringArray -{ +impl> From>> for MultiLineStringArray { fn from(other: Vec>) -> Self { let mut_arr: MultiLineStringBuilder = other.into(); mut_arr.into() } } -impl, const D: usize> From<&[G]> for MultiLineStringArray { +impl> From<&[G]> for MultiLineStringArray { fn from(other: &[G]) -> Self { let mut_arr: MultiLineStringBuilder = other.into(); mut_arr.into() @@ -493,7 +492,7 @@ impl From for PolygonArray { } } -impl TryFrom> for MultiLineStringArray { +impl TryFrom> for MultiLineStringArray { type Error = GeoArrowError; fn try_from(value: WKBArray) -> Result { @@ -565,6 +564,7 @@ impl TryFrom for MultiLineStringArray { capacity += value.line_strings.buffer_lengths(); let mut builder = MultiLineStringBuilder::with_capacity_and_options( + value.dim(), capacity, value.coord_type(), value.metadata(), diff --git a/rust/geoarrow/src/array/multipoint/array.rs b/rust/geoarrow/src/array/multipoint/array.rs index 37c9421c..bfbd5e05 100644 --- a/rust/geoarrow/src/array/multipoint/array.rs +++ b/rust/geoarrow/src/array/multipoint/array.rs @@ -9,7 +9,7 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, LineStringArray, MixedGeometryArray, PointArray, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiPoint}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -333,11 +333,11 @@ impl IntoArrow for MultiPointArray { } } -impl TryFrom<&GenericListArray> for MultiPointArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiPointArray { type Error = GeoArrowError; - fn try_from(value: &GenericListArray) -> Result { - let coords = CoordBuffer::from_arrow(value.values().as_ref(), D.try_into()?)?; + fn try_from((value, dim): (&GenericListArray, Dimension)) -> Result { + let coords = CoordBuffer::from_arrow(value.values().as_ref(), dim)?; let geom_offsets = value.offsets(); let validity = value.nulls(); @@ -350,11 +350,11 @@ impl TryFrom<&GenericListArray> for MultiPointArray { } } -impl TryFrom<&GenericListArray> for MultiPointArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiPointArray { type Error = GeoArrowError; - fn try_from(value: &GenericListArray) -> Result { - let coords = CoordBuffer::from_arrow(value.values().as_ref(), D.try_into()?)?; + fn try_from((value, dim): (&GenericListArray, Dimension)) -> Result { + let coords = CoordBuffer::from_arrow(value.values().as_ref(), dim)?; let geom_offsets = offsets_buffer_i64_to_i32(value.offsets())?; let validity = value.nulls(); @@ -367,18 +367,18 @@ impl TryFrom<&GenericListArray> for MultiPointArray { } } -impl TryFrom<&dyn Array> for MultiPointArray { +impl TryFrom<(&dyn Array, Dimension)> for MultiPointArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::List(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } DataType::LargeList(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } _ => Err(GeoArrowError::General(format!( "Unexpected type: {:?}", @@ -392,27 +392,28 @@ impl TryFrom<(&dyn Array, &Field)> for MultiPointArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } } -impl, const D: usize> From>> for MultiPointArray { +impl> From>> for MultiPointArray { fn from(other: Vec>) -> Self { let mut_arr: MultiPointBuilder = other.into(); mut_arr.into() } } -impl, const D: usize> From<&[G]> for MultiPointArray { +impl> From<&[G]> for MultiPointArray { fn from(other: &[G]) -> Self { let mut_arr: MultiPointBuilder = other.into(); mut_arr.into() } } -impl TryFrom> for MultiPointArray { +impl TryFrom> for MultiPointArray { type Error = GeoArrowError; fn try_from(value: WKBArray) -> Result { diff --git a/rust/geoarrow/src/array/multipolygon/array.rs b/rust/geoarrow/src/array/multipolygon/array.rs index 5fe8a981..2ef32b33 100644 --- a/rust/geoarrow/src/array/multipolygon/array.rs +++ b/rust/geoarrow/src/array/multipolygon/array.rs @@ -7,7 +7,7 @@ use crate::array::util::{offsets_buffer_i64_to_i32, OffsetBufferUtils}; use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, PolygonArray, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiPolygon}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -470,10 +470,10 @@ impl IntoArrow for MultiPolygonArray { } } -impl TryFrom<&GenericListArray> for MultiPolygonArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiPolygonArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = geom_array.offsets(); let validity = geom_array.nulls(); @@ -485,7 +485,7 @@ impl TryFrom<&GenericListArray> for MultiPolygonArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = rings_array.offsets(); - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -498,10 +498,10 @@ impl TryFrom<&GenericListArray> for MultiPolygonArray { } } -impl TryFrom<&GenericListArray> for MultiPolygonArray { +impl TryFrom<(&GenericListArray, Dimension)> for MultiPolygonArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = offsets_buffer_i64_to_i32(geom_array.offsets())?; let validity = geom_array.nulls(); @@ -513,7 +513,7 @@ impl TryFrom<&GenericListArray> for MultiPolygonArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = offsets_buffer_i64_to_i32(rings_array.offsets())?; - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -526,18 +526,18 @@ impl TryFrom<&GenericListArray> for MultiPolygonArray { } } -impl TryFrom<&dyn Array> for MultiPolygonArray { +impl TryFrom<(&dyn Array, Dimension)> for MultiPolygonArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::List(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } DataType::LargeList(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } _ => Err(GeoArrowError::General(format!( "Unexpected type: {:?}", @@ -551,27 +551,28 @@ impl TryFrom<(&dyn Array, &Field)> for MultiPolygonArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } } -impl, const D: usize> From>> for MultiPolygonArray { +impl> From>> for MultiPolygonArray { fn from(other: Vec>) -> Self { let mut_arr: MultiPolygonBuilder = other.into(); mut_arr.into() } } -impl, const D: usize> From<&[G]> for MultiPolygonArray { +impl> From<&[G]> for MultiPolygonArray { fn from(other: &[G]) -> Self { let mut_arr: MultiPolygonBuilder = other.into(); mut_arr.into() } } -impl TryFrom> for MultiPolygonArray { +impl TryFrom> for MultiPolygonArray { type Error = GeoArrowError; fn try_from(value: WKBArray) -> Result { diff --git a/rust/geoarrow/src/array/point/array.rs b/rust/geoarrow/src/array/point/array.rs index f188b924..7d44bc68 100644 --- a/rust/geoarrow/src/array/point/array.rs +++ b/rust/geoarrow/src/array/point/array.rs @@ -7,7 +7,7 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, InterleavedCoordBuffer, MixedGeometryArray, MultiPointArray, PointBuilder, SeparatedCoordBuffer, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, Point}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -267,7 +267,7 @@ impl IntoArrow for PointArray { match self.coords { CoordBuffer::Interleaved(c) => Arc::new(FixedSizeListArray::new( c.values_field().into(), - D as i32, + self.coords.dim().size() as i32, Arc::new(c.values_array()), validity, )), @@ -279,11 +279,11 @@ impl IntoArrow for PointArray { } } -impl TryFrom<&FixedSizeListArray> for PointArray { +impl TryFrom<(&FixedSizeListArray, Dimension)> for PointArray { type Error = GeoArrowError; - fn try_from(value: &FixedSizeListArray) -> Result { - let interleaved_coords = InterleavedCoordBuffer::from_arrow(value, D.try_into()?)?; + fn try_from((value, dim): (&FixedSizeListArray, Dimension)) -> Result { + let interleaved_coords = InterleavedCoordBuffer::from_arrow(value, dim)?; Ok(Self::new( CoordBuffer::Interleaved(interleaved_coords), @@ -293,12 +293,12 @@ impl TryFrom<&FixedSizeListArray> for PointArray { } } -impl TryFrom<&StructArray> for PointArray { +impl TryFrom<(&StructArray, Dimension)> for PointArray { type Error = GeoArrowError; - fn try_from(value: &StructArray) -> Result { + fn try_from((value, dim): (&StructArray, Dimension)) -> Result { let validity = value.nulls(); - let separated_coords = SeparatedCoordBuffer::from_arrow(value, D.try_into()?)?; + let separated_coords = SeparatedCoordBuffer::from_arrow(value, dim)?; Ok(Self::new( CoordBuffer::Separated(separated_coords), validity.cloned(), @@ -307,18 +307,18 @@ impl TryFrom<&StructArray> for PointArray { } } -impl TryFrom<&dyn Array> for PointArray { +impl TryFrom<(&dyn Array, Dimension)> for PointArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::FixedSizeList(_, _) => { let arr = value.as_any().downcast_ref::().unwrap(); - arr.try_into() + (arr, dim).try_into() } DataType::Struct(_) => { let arr = value.as_any().downcast_ref::().unwrap(); - arr.try_into() + (arr, dim).try_into() } _ => Err(GeoArrowError::General( "Invalid data type for PointArray".to_string(), @@ -331,27 +331,28 @@ impl TryFrom<(&dyn Array, &Field)> for PointArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } } -impl, const D: usize> From>> for PointArray { +impl> From>> for PointArray { fn from(other: Vec>) -> Self { let mut_arr: PointBuilder = other.into(); mut_arr.into() } } -impl, const D: usize> From<&[G]> for PointArray { +impl> From<&[G]> for PointArray { fn from(other: &[G]) -> Self { let mut_arr: PointBuilder = other.into(); mut_arr.into() } } -impl TryFrom> for PointArray { +impl TryFrom> for PointArray { type Error = GeoArrowError; fn try_from(value: WKBArray) -> Result { diff --git a/rust/geoarrow/src/array/polygon/array.rs b/rust/geoarrow/src/array/polygon/array.rs index 92150ceb..7c4facdd 100644 --- a/rust/geoarrow/src/array/polygon/array.rs +++ b/rust/geoarrow/src/array/polygon/array.rs @@ -9,7 +9,7 @@ use crate::array::{ CoordBuffer, CoordType, GeometryCollectionArray, MixedGeometryArray, MultiLineStringArray, MultiPolygonArray, RectArray, WKBArray, }; -use crate::datatypes::NativeType; +use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, Polygon}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; @@ -389,10 +389,10 @@ impl IntoArrow for PolygonArray { } } -impl TryFrom<&GenericListArray> for PolygonArray { +impl TryFrom<(&GenericListArray, Dimension)> for PolygonArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = geom_array.offsets(); let validity = geom_array.nulls(); @@ -400,7 +400,7 @@ impl TryFrom<&GenericListArray> for PolygonArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = rings_array.offsets(); - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -412,10 +412,10 @@ impl TryFrom<&GenericListArray> for PolygonArray { } } -impl TryFrom<&GenericListArray> for PolygonArray { +impl TryFrom<(&GenericListArray, Dimension)> for PolygonArray { type Error = GeoArrowError; - fn try_from(geom_array: &GenericListArray) -> Result { + fn try_from((geom_array, dim): (&GenericListArray, Dimension)) -> Result { let geom_offsets = offsets_buffer_i64_to_i32(geom_array.offsets())?; let validity = geom_array.nulls(); @@ -423,7 +423,7 @@ impl TryFrom<&GenericListArray> for PolygonArray { let rings_array = rings_dyn_array.as_list::(); let ring_offsets = offsets_buffer_i64_to_i32(rings_array.offsets())?; - let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), D.try_into()?)?; + let coords = CoordBuffer::from_arrow(rings_array.values().as_ref(), dim)?; Ok(Self::new( coords, @@ -434,18 +434,18 @@ impl TryFrom<&GenericListArray> for PolygonArray { )) } } -impl TryFrom<&dyn Array> for PolygonArray { +impl TryFrom<(&dyn Array, Dimension)> for PolygonArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::List(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } DataType::LargeList(_) => { let downcasted = value.as_list::(); - downcasted.try_into() + (downcasted, dim).try_into() } _ => Err(GeoArrowError::General(format!( "Unexpected type: {:?}", @@ -459,7 +459,8 @@ impl TryFrom<(&dyn Array, &Field)> for PolygonArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } diff --git a/rust/geoarrow/src/array/rect/array.rs b/rust/geoarrow/src/array/rect/array.rs index 844acfe5..93f2fa8a 100644 --- a/rust/geoarrow/src/array/rect/array.rs +++ b/rust/geoarrow/src/array/rect/array.rs @@ -9,7 +9,7 @@ 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, NativeType}; +use crate::datatypes::{rect_fields, Dimension, NativeType}; use crate::error::GeoArrowError; use crate::scalar::Rect; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; @@ -47,7 +47,8 @@ impl RectArray { validity: Option, metadata: Arc, ) -> Self { - let data_type = NativeType::Rect(D.try_into().unwrap()); + assert_eq!(lower.dim(), upper.dim()); + let data_type = NativeType::Rect(lower.dim()); Self { data_type, lower, @@ -191,7 +192,7 @@ impl IntoArrow for RectArray { type ArrowArray = StructArray; fn into_arrow(self) -> Self::ArrowArray { - let fields = rect_fields(D.try_into().unwrap()); + let fields = rect_fields(self.data_type.dimension()); let mut arrays: Vec = vec![]; for buf in self.lower.buffers { arrays.push(Arc::new(Float64Array::new(buf, None))); @@ -205,50 +206,48 @@ impl IntoArrow for RectArray { } } -impl TryFrom<&StructArray> for RectArray { +impl TryFrom<(&StructArray, Dimension)> for RectArray { type Error = GeoArrowError; - fn try_from(value: &StructArray) -> Result { + fn try_from((value, dim): (&StructArray, Dimension)) -> Result { let validity = value.nulls(); let columns = value.columns(); - assert_eq!(columns.len(), D * 2); + assert_eq!(columns.len(), dim.size() * 2); - let lower = match D { - 2 => { + let lower = match dim { + Dimension::XY => { core::array::from_fn(|i| columns[i].as_primitive::().values().clone()) } - 3 => { + Dimension::XYZ => { core::array::from_fn(|i| columns[i].as_primitive::().values().clone()) } - _ => panic!("unexpected dim"), }; - let upper = match D { - 2 => { + let upper = match dim { + Dimension::XY => { core::array::from_fn(|i| columns[i].as_primitive::().values().clone()) } - 3 => { + Dimension::XYZ => { core::array::from_fn(|i| columns[i].as_primitive::().values().clone()) } - _ => panic!("unexpected dim"), }; Ok(Self::new( - SeparatedCoordBuffer::new(lower, D.try_into().unwrap()), - SeparatedCoordBuffer::new(upper, D.try_into().unwrap()), + SeparatedCoordBuffer::new(lower, dim), + SeparatedCoordBuffer::new(upper, dim), validity.cloned(), Default::default(), )) } } -impl TryFrom<&dyn Array> for RectArray { +impl TryFrom<(&dyn Array, Dimension)> for RectArray { type Error = GeoArrowError; - fn try_from(value: &dyn Array) -> Result { + fn try_from((value, dim): (&dyn Array, Dimension)) -> Result { match value.data_type() { DataType::Struct(_) => { let arr = value.as_any().downcast_ref::().unwrap(); - arr.try_into() + (arr, dim).try_into() } _ => Err(GeoArrowError::General( "Invalid data type for RectArray".to_string(), @@ -261,20 +260,21 @@ impl TryFrom<(&dyn Array, &Field)> for RectArray { type Error = GeoArrowError; fn try_from((arr, field): (&dyn Array, &Field)) -> Result { - let mut arr: Self = arr.try_into()?; + let geom_type = NativeType::try_from(field)?; + let mut arr: Self = (arr, geom_type.dimension()).try_into()?; arr.metadata = Arc::new(ArrayMetadata::try_from(field)?); Ok(arr) } } -impl, const D: usize> From<&[G]> for RectArray { +impl> From<&[G]> for RectArray { fn from(other: &[G]) -> Self { let mut_arr: RectBuilder = other.into(); mut_arr.into() } } -impl, const D: usize> From>> for RectArray { +impl> From>> for RectArray { fn from(other: Vec>) -> Self { let mut_arr: RectBuilder = other.into(); mut_arr.into() diff --git a/rust/geoarrow/src/datatypes.rs b/rust/geoarrow/src/datatypes.rs index 660c4b16..f9453d8e 100644 --- a/rust/geoarrow/src/datatypes.rs +++ b/rust/geoarrow/src/datatypes.rs @@ -990,7 +990,7 @@ mod test { let data_type: NativeType = field.as_ref().try_into().unwrap(); assert_eq!(ml_array.data_type(), data_type); - let mut builder = MixedGeometryBuilder::<2>::new(); + let mut builder = MixedGeometryBuilder::new(); builder.push_point(Some(&crate::test::point::p0())).unwrap(); builder.push_point(Some(&crate::test::point::p1())).unwrap(); builder.push_point(Some(&crate::test::point::p2())).unwrap(); diff --git a/rust/geoarrow/src/scalar/geometry/owned.rs b/rust/geoarrow/src/scalar/geometry/owned.rs index 4a305e80..8293c351 100644 --- a/rust/geoarrow/src/scalar/geometry/owned.rs +++ b/rust/geoarrow/src/scalar/geometry/owned.rs @@ -36,8 +36,8 @@ impl<'a> From<&'a OwnedGeometry> for Geometry<'a> { } } -impl<'a> From<&'a OwnedGeometry<2>> for geo::Geometry { - fn from(value: &'a OwnedGeometry<2>) -> Self { +impl<'a> From<&'a OwnedGeometry> for geo::Geometry { + fn from(value: &'a OwnedGeometry) -> Self { let geom = Geometry::from(value); geom.into() } diff --git a/rust/geoarrow/src/scalar/geometrycollection/owned.rs b/rust/geoarrow/src/scalar/geometrycollection/owned.rs index b534b2e1..dc747eca 100644 --- a/rust/geoarrow/src/scalar/geometrycollection/owned.rs +++ b/rust/geoarrow/src/scalar/geometrycollection/owned.rs @@ -7,7 +7,7 @@ use geo_traits::GeometryCollectionTrait; #[derive(Clone, Debug)] pub struct OwnedGeometryCollection { - array: MixedGeometryArray, + array: MixedGeometryArray, /// Offsets into the geometry array where each geometry starts geom_offsets: OffsetBuffer, @@ -15,9 +15,9 @@ pub struct OwnedGeometryCollection { geom_index: usize, } -impl OwnedGeometryCollection { +impl OwnedGeometryCollection { pub fn new( - array: MixedGeometryArray, + array: MixedGeometryArray, geom_offsets: OffsetBuffer, geom_index: usize, ) -> Self { @@ -29,33 +29,33 @@ impl OwnedGeometryCollection { } } -impl<'a> From<&'a OwnedGeometryCollection> for GeometryCollection<'a> { - fn from(value: &'a OwnedGeometryCollection) -> Self { +impl<'a> From<&'a OwnedGeometryCollection> for GeometryCollection<'a> { + fn from(value: &'a OwnedGeometryCollection) -> Self { Self::new(&value.array, &value.geom_offsets, value.geom_index) } } -impl<'a> From<&'a OwnedGeometryCollection<2>> for geo::GeometryCollection { - fn from(value: &'a OwnedGeometryCollection<2>) -> Self { +impl<'a> From<&'a OwnedGeometryCollection> for geo::GeometryCollection { + fn from(value: &'a OwnedGeometryCollection) -> Self { let geom = GeometryCollection::from(value); geom.into() } } -impl<'a> From> for OwnedGeometryCollection { +impl<'a> From> for OwnedGeometryCollection { fn from(value: GeometryCollection<'a>) -> Self { let (array, geom_offsets, geom_index) = value.into_inner(); Self::new(array.clone(), geom_offsets.clone(), geom_index) } } -impl From> for GeometryCollectionArray { - fn from(value: OwnedGeometryCollection) -> Self { +impl From for GeometryCollectionArray { + fn from(value: OwnedGeometryCollection) -> Self { Self::new(value.array, value.geom_offsets, None, Default::default()) } } -impl GeometryCollectionTrait for OwnedGeometryCollection { +impl GeometryCollectionTrait for OwnedGeometryCollection { type T = f64; type GeometryType<'b> = Geometry<'b> where Self: 'b; @@ -75,7 +75,7 @@ impl GeometryCollectionTrait for OwnedGeometryCollection { } } -impl> PartialEq for OwnedGeometryCollection<2> { +impl> PartialEq for OwnedGeometryCollection { fn eq(&self, other: &G) -> bool { geometry_collection_eq(self, other) } diff --git a/rust/geoarrow/src/scalar/geometrycollection/scalar.rs b/rust/geoarrow/src/scalar/geometrycollection/scalar.rs index a662b93b..2a3ca9b3 100644 --- a/rust/geoarrow/src/scalar/geometrycollection/scalar.rs +++ b/rust/geoarrow/src/scalar/geometrycollection/scalar.rs @@ -13,7 +13,7 @@ use rstar::{RTreeObject, AABB}; /// An Arrow equivalent of a GeometryCollection #[derive(Debug, Clone)] pub struct GeometryCollection<'a> { - pub(crate) array: &'a MixedGeometryArray, + pub(crate) array: &'a MixedGeometryArray, /// Offsets into the geometry array where each geometry starts pub(crate) geom_offsets: &'a OffsetBuffer, @@ -25,7 +25,7 @@ pub struct GeometryCollection<'a> { impl<'a> GeometryCollection<'a> { pub fn new( - array: &'a MixedGeometryArray, + array: &'a MixedGeometryArray, geom_offsets: &'a OffsetBuffer, geom_index: usize, ) -> Self { @@ -38,7 +38,7 @@ impl<'a> GeometryCollection<'a> { } } - pub fn into_inner(&self) -> (&MixedGeometryArray, &OffsetBuffer, usize) { + pub fn into_inner(&self) -> (&MixedGeometryArray, &OffsetBuffer, usize) { (self.array, self.geom_offsets, self.geom_index) } } @@ -65,7 +65,7 @@ impl<'a> GeometryCollectionTrait for GeometryCollection<'a> { type GeometryType<'b> = Geometry<'a> 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, } @@ -86,7 +86,7 @@ impl<'a> GeometryCollectionTrait for &'a GeometryCollection<'a> { type GeometryType<'b> = Geometry<'a> 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, } @@ -114,7 +114,7 @@ impl From> for geo::Geometry { } } -impl RTreeObject for GeometryCollection<'_, 2> { +impl RTreeObject for GeometryCollection<'_> { type Envelope = AABB<[f64; 2]>; fn envelope(&self) -> Self::Envelope { diff --git a/rust/geoarrow/src/scalar/linestring/scalar.rs b/rust/geoarrow/src/scalar/linestring/scalar.rs index e76dfc86..2bc21196 100644 --- a/rust/geoarrow/src/scalar/linestring/scalar.rs +++ b/rust/geoarrow/src/scalar/linestring/scalar.rs @@ -145,8 +145,8 @@ mod test { /// Test Eq where the current index is true but another index is false #[test] fn test_eq_other_index_false() { - let arr1: LineStringArray<2> = vec![ls0(), ls1()].as_slice().into(); - let arr2: LineStringArray<2> = vec![ls0(), ls0()].as_slice().into(); + let arr1: LineStringArray = vec![ls0(), ls1()].as_slice().into(); + let arr2: LineStringArray = vec![ls0(), ls0()].as_slice().into(); assert_eq!(arr1.value(0), arr2.value(0)); assert_ne!(arr1.value(1), arr2.value(1)); diff --git a/rust/geoarrow/src/scalar/multilinestring/owned.rs b/rust/geoarrow/src/scalar/multilinestring/owned.rs index 4676ec3c..5d4d5bb0 100644 --- a/rust/geoarrow/src/scalar/multilinestring/owned.rs +++ b/rust/geoarrow/src/scalar/multilinestring/owned.rs @@ -44,8 +44,8 @@ impl<'a> From<&'a OwnedMultiLineString> for MultiLineString<'a> { } } -impl From> for geo::MultiLineString { - fn from(value: OwnedMultiLineString<2>) -> Self { +impl From for geo::MultiLineString { + fn from(value: OwnedMultiLineString) -> Self { let geom = MultiLineString::from(&value); geom.into() } @@ -90,7 +90,7 @@ impl MultiLineStringTrait for OwnedMultiLineString { } } -impl> PartialEq for OwnedMultiLineString<2> { +impl> PartialEq for OwnedMultiLineString { fn eq(&self, other: &G) -> bool { multi_line_string_eq(self, other) } diff --git a/rust/geoarrow/src/scalar/multilinestring/scalar.rs b/rust/geoarrow/src/scalar/multilinestring/scalar.rs index 12e63a8c..67edeb37 100644 --- a/rust/geoarrow/src/scalar/multilinestring/scalar.rs +++ b/rust/geoarrow/src/scalar/multilinestring/scalar.rs @@ -131,7 +131,7 @@ impl From> for geo::Geometry { } } -impl RTreeObject for MultiLineString<'_, 2> { +impl RTreeObject for MultiLineString<'_> { type Envelope = AABB<[f64; 2]>; fn envelope(&self) -> Self::Envelope { @@ -140,7 +140,7 @@ impl RTreeObject for MultiLineString<'_, 2> { } } -impl> PartialEq for MultiLineString<'_, 2> { +impl> PartialEq for MultiLineString<'_> { fn eq(&self, other: &G) -> bool { multi_line_string_eq(self, other) } @@ -155,8 +155,8 @@ mod test { /// Test Eq where the current index is true but another index is false #[test] fn test_eq_other_index_false() { - let arr1: MultiLineStringArray<2> = vec![ml0(), ml1()].as_slice().into(); - let arr2: MultiLineStringArray<2> = vec![ml0(), ml0()].as_slice().into(); + let arr1: MultiLineStringArray = vec![ml0(), ml1()].as_slice().into(); + let arr2: MultiLineStringArray = vec![ml0(), ml0()].as_slice().into(); assert_eq!(arr1.value(0), arr2.value(0)); assert_ne!(arr1.value(1), arr2.value(1)); diff --git a/rust/geoarrow/src/scalar/multipoint/scalar.rs b/rust/geoarrow/src/scalar/multipoint/scalar.rs index 70be00d7..331ed044 100644 --- a/rust/geoarrow/src/scalar/multipoint/scalar.rs +++ b/rust/geoarrow/src/scalar/multipoint/scalar.rs @@ -129,7 +129,7 @@ impl From> for geo::Geometry { } } -impl RTreeObject for MultiPoint<'_, 2> { +impl RTreeObject for MultiPoint<'_> { type Envelope = AABB<[f64; 2]>; fn envelope(&self) -> Self::Envelope { @@ -153,8 +153,8 @@ mod test { /// Test Eq where the current index is true but another index is false #[test] fn test_eq_other_index_false() { - let arr1: MultiPointArray<2> = vec![mp0(), mp1()].as_slice().into(); - let arr2: MultiPointArray<2> = vec![mp0(), mp0()].as_slice().into(); + let arr1: MultiPointArray = vec![mp0(), mp1()].as_slice().into(); + let arr2: MultiPointArray = vec![mp0(), mp0()].as_slice().into(); assert_eq!(arr1.value(0), arr2.value(0)); assert_ne!(arr1.value(1), arr2.value(1)); diff --git a/rust/geoarrow/src/scalar/multipolygon/scalar.rs b/rust/geoarrow/src/scalar/multipolygon/scalar.rs index 6e71d4d8..851ab92a 100644 --- a/rust/geoarrow/src/scalar/multipolygon/scalar.rs +++ b/rust/geoarrow/src/scalar/multipolygon/scalar.rs @@ -183,8 +183,8 @@ mod test { /// Test Eq where the current index is true but another index is false #[test] fn test_eq_other_index_false() { - let arr1: MultiPolygonArray<2> = vec![mp0(), mp1()].as_slice().into(); - let arr2: MultiPolygonArray<2> = vec![mp0(), mp0()].as_slice().into(); + let arr1: MultiPolygonArray = vec![mp0(), mp1()].as_slice().into(); + let arr2: MultiPolygonArray = vec![mp0(), mp0()].as_slice().into(); assert_eq!(arr1.value(0), arr2.value(0)); assert_ne!(arr1.value(1), arr2.value(1)); diff --git a/rust/geoarrow/src/scalar/point/scalar.rs b/rust/geoarrow/src/scalar/point/scalar.rs index a9b5c46f..288e5dd9 100644 --- a/rust/geoarrow/src/scalar/point/scalar.rs +++ b/rust/geoarrow/src/scalar/point/scalar.rs @@ -126,12 +126,12 @@ mod test { let x1 = vec![0., 1., 2.]; let y1 = vec![3., 4., 5.]; let buf1 = CoordBuffer::Separated((x1, y1).try_into().unwrap()); - let arr1 = PointArray::<2>::new(buf1, None, Default::default()); + let arr1 = PointArray::new(buf1, None, Default::default()); let x2 = vec![0., 100., 2.]; let y2 = vec![3., 400., 5.]; let buf2 = CoordBuffer::Separated((x2, y2).try_into().unwrap()); - let arr2 = PointArray::<2>::new(buf2, None, Default::default()); + let arr2 = PointArray::new(buf2, None, Default::default()); assert_eq!(arr1.value(0), arr2.value(0)); } diff --git a/rust/geoarrow/src/scalar/polygon/owned.rs b/rust/geoarrow/src/scalar/polygon/owned.rs index d6c7d8af..7fbe789a 100644 --- a/rust/geoarrow/src/scalar/polygon/owned.rs +++ b/rust/geoarrow/src/scalar/polygon/owned.rs @@ -17,7 +17,7 @@ pub struct OwnedPolygon { geom_index: usize, } -impl OwnedPolygon { +impl OwnedPolygon { pub fn new( coords: CoordBuffer, geom_offsets: OffsetBuffer, @@ -33,8 +33,8 @@ impl OwnedPolygon { } } -impl<'a> From<&'a OwnedPolygon> for Polygon<'a> { - fn from(value: &'a OwnedPolygon) -> Self { +impl<'a> From<&'a OwnedPolygon> for Polygon<'a> { + fn from(value: &'a OwnedPolygon) -> Self { Self::new( &value.coords, &value.geom_offsets, @@ -44,22 +44,22 @@ impl<'a> From<&'a OwnedPolygon> for Polygon<'a> { } } -impl From> for geo::Polygon { - fn from(value: OwnedPolygon<2>) -> Self { +impl From for geo::Polygon { + fn from(value: OwnedPolygon) -> Self { let geom = Polygon::from(&value); geom.into() } } -impl<'a> From> for OwnedPolygon { +impl<'a> From> for OwnedPolygon { fn from(value: Polygon<'a>) -> Self { let (coords, geom_offsets, ring_offsets, geom_index) = value.into_owned_inner(); Self::new(coords, geom_offsets, ring_offsets, geom_index) } } -impl From> for PolygonArray { - fn from(value: OwnedPolygon) -> Self { +impl From for PolygonArray { + fn from(value: OwnedPolygon) -> Self { Self::new( value.coords, value.geom_offsets, @@ -70,9 +70,9 @@ impl From> for PolygonArray { } } -impl PolygonTrait for OwnedPolygon { +impl PolygonTrait for OwnedPolygon { type T = f64; - type RingType<'b> = LineString<'b, D> where Self: 'b; + type RingType<'b> = LineString<'b> where Self: 'b; fn dim(&self) -> geo_traits::Dimensions { match self.coords.dim() { @@ -94,7 +94,7 @@ impl PolygonTrait for OwnedPolygon { } } -impl> PartialEq for OwnedPolygon<2> { +impl> PartialEq for OwnedPolygon { fn eq(&self, other: &G) -> bool { polygon_eq(self, other) } diff --git a/rust/geoarrow/src/scalar/polygon/scalar.rs b/rust/geoarrow/src/scalar/polygon/scalar.rs index cbc7294d..cf157d9b 100644 --- a/rust/geoarrow/src/scalar/polygon/scalar.rs +++ b/rust/geoarrow/src/scalar/polygon/scalar.rs @@ -157,7 +157,7 @@ impl From> for geo::Geometry { } } -impl RTreeObject for Polygon<'_, 2> { +impl RTreeObject for Polygon<'_> { type Envelope = AABB<[f64; 2]>; fn envelope(&self) -> Self::Envelope { @@ -181,8 +181,8 @@ mod test { /// Test Eq where the current index is true but another index is false #[test] fn test_eq_other_index_false() { - let arr1: PolygonArray<2> = vec![p0(), p1()].as_slice().into(); - let arr2: PolygonArray<2> = vec![p0(), p0()].as_slice().into(); + let arr1: PolygonArray = vec![p0(), p1()].as_slice().into(); + let arr2: PolygonArray = vec![p0(), p0()].as_slice().into(); assert_eq!(arr1.value(0), arr2.value(0)); assert_ne!(arr1.value(1), arr2.value(1)); diff --git a/rust/geoarrow/src/scalar/rect/owned.rs b/rust/geoarrow/src/scalar/rect/owned.rs index 1474db11..4d3fc1d4 100644 --- a/rust/geoarrow/src/scalar/rect/owned.rs +++ b/rust/geoarrow/src/scalar/rect/owned.rs @@ -1,5 +1,6 @@ use crate::algorithm::native::eq::rect_eq; use crate::array::{RectArray, SeparatedCoordBuffer}; +use crate::datatypes::Dimension; use crate::scalar::{Rect, SeparatedCoord}; use geo_traits::RectTrait; @@ -10,7 +11,7 @@ pub struct OwnedRect { geom_index: usize, } -impl OwnedRect { +impl OwnedRect { pub fn new( lower: SeparatedCoordBuffer, upper: SeparatedCoordBuffer, @@ -24,31 +25,31 @@ impl OwnedRect { } } -impl<'a> From<&'a OwnedRect> for Rect<'a> { - fn from(value: &'a OwnedRect) -> Self { +impl<'a> From<&'a OwnedRect> for Rect<'a> { + fn from(value: &'a OwnedRect) -> Self { Self::new(&value.lower, &value.upper, value.geom_index) } } -impl<'a> From> for OwnedRect { +impl<'a> From> for OwnedRect { fn from(value: Rect<'a>) -> Self { let (lower, upper, geom_index) = value.into_owned_inner(); Self::new(lower, upper, geom_index) } } -impl From> for RectArray { - fn from(value: OwnedRect) -> Self { +impl From for RectArray { + fn from(value: OwnedRect) -> Self { Self::new(value.lower, value.upper, None, Default::default()) } } -impl RectTrait for OwnedRect { +impl RectTrait for OwnedRect { type T = f64; type CoordType<'b> = SeparatedCoord<'b> where Self: 'b; fn dim(&self) -> geo_traits::Dimensions { - match self.coords.dim() { + match self.lower.dim() { Dimension::XY => geo_traits::Dimensions::Xy, Dimension::XYZ => geo_traits::Dimensions::Xyz, } @@ -63,7 +64,7 @@ impl RectTrait for OwnedRect { } } -impl> PartialEq for OwnedRect<2> { +impl> PartialEq for OwnedRect { fn eq(&self, other: &G) -> bool { rect_eq(self, other) } diff --git a/rust/geoarrow/src/scalar/scalar.rs b/rust/geoarrow/src/scalar/scalar.rs index 5487ae28..b314383a 100644 --- a/rust/geoarrow/src/scalar/scalar.rs +++ b/rust/geoarrow/src/scalar/scalar.rs @@ -71,52 +71,43 @@ impl GeometryScalar { // Note: we use `.downcast_ref` directly here because we need to pass in the generic // TODO: may be able to change this now that we don't have + // + // TODO: as of Nov 2024 we should be able to switch back to the downcasting helpers + match self.data_type() { Point(_, _) => { - let arr = self.0.as_any().downcast_ref::>().unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::Point) } LineString(_, _) => { - let arr = self - .0 - .as_any() - .downcast_ref::>() - .unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::LineString) } Polygon(_, _) => { - let arr = self.0.as_any().downcast_ref::>().unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::Polygon) } MultiPoint(_, _) => { - let arr = self - .0 - .as_any() - .downcast_ref::>() - .unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::MultiPoint) } MultiLineString(_, _) => { let arr = self .0 .as_any() - .downcast_ref::>() + .downcast_ref::() .unwrap(); arr.get(0).map(Geometry::MultiLineString) } MultiPolygon(_, _) => { - let arr = self - .0 - .as_any() - .downcast_ref::>() - .unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::MultiPolygon) } Mixed(_, _) => { let arr = self .0 .as_any() - .downcast_ref::>() + .downcast_ref::() .unwrap(); arr.get(0) } @@ -124,12 +115,12 @@ impl GeometryScalar { let arr = self .0 .as_any() - .downcast_ref::>() + .downcast_ref::() .unwrap(); arr.get(0).map(Geometry::GeometryCollection) } Rect(_) => { - let arr = self.0.as_any().downcast_ref::>().unwrap(); + let arr = self.0.as_any().downcast_ref::().unwrap(); arr.get(0).map(Geometry::Rect) } } @@ -137,57 +128,23 @@ impl GeometryScalar { pub fn to_geo(&self) -> geo::Geometry { macro_rules! impl_to_geo { - ($cast_func:ident, $dim:expr) => {{ - self.0 - .as_ref() - .$cast_func::<$dim>() - .value(0) - .to_geo_geometry() + ($cast_func:ident) => {{ + self.0.as_ref().$cast_func().value(0).to_geo_geometry() }}; } - use Dimension::*; use NativeType::*; match self.data_type() { - Point(_, XY) => impl_to_geo!(as_point, 2), - LineString(_, XY) => impl_to_geo!(as_line_string, 2), - Polygon(_, XY) => impl_to_geo!(as_polygon, 2), - MultiPoint(_, XY) => impl_to_geo!(as_multi_point, 2), - MultiLineString(_, XY) => { - impl_to_geo!(as_multi_line_string, 2) - } - MultiPolygon(_, XY) => impl_to_geo!(as_multi_polygon, 2), - Mixed(_, XY) => impl_to_geo!(as_mixed, 2), - GeometryCollection(_, XY) => { - impl_to_geo!(as_geometry_collection, 2) - } - Rect(XY) => impl_to_geo!(as_rect, 2), - Point(_, XYZ) => impl_to_geo!(as_point, 3), - LineString(_, XYZ) => impl_to_geo!(as_line_string, 3), - Polygon(_, XYZ) => impl_to_geo!(as_polygon, 3), - MultiPoint(_, XYZ) => impl_to_geo!(as_multi_point, 3), - MultiLineString(_, XYZ) => { - impl_to_geo!(as_multi_line_string, 3) - } - MultiPolygon(_, XYZ) => impl_to_geo!(as_multi_polygon, 3), - Mixed(_, XYZ) => impl_to_geo!(as_mixed, 3), - GeometryCollection(_, XYZ) => { - impl_to_geo!(as_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) - // } + Point(_, _) => impl_to_geo!(as_point), + LineString(_, _) => impl_to_geo!(as_line_string), + Polygon(_, _) => impl_to_geo!(as_polygon), + MultiPoint(_, _) => impl_to_geo!(as_multi_point), + MultiLineString(_, _) => impl_to_geo!(as_multi_line_string), + MultiPolygon(_, _) => impl_to_geo!(as_multi_polygon), + Mixed(_, _) => impl_to_geo!(as_mixed), + GeometryCollection(_, _) => impl_to_geo!(as_geometry_collection), + Rect(_) => impl_to_geo!(as_rect), } } diff --git a/rust/geoarrow/src/trait_.rs b/rust/geoarrow/src/trait_.rs index a4168eb0..5b86ccf9 100644 --- a/rust/geoarrow/src/trait_.rs +++ b/rust/geoarrow/src/trait_.rs @@ -814,7 +814,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// ``` /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; /// - /// let mut builder = PointBuilder::<2>::new(); + /// let mut builder = PointBuilder::new(Dimension::XY); /// assert_eq!(builder.len(), 0); /// builder.push_point(Some(&geo::point!(x: 1., y: 2.))); /// assert_eq!(builder.len(), 1); @@ -828,7 +828,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// ``` /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; /// - /// let mut builder = PointBuilder::<2>::new(); + /// let mut builder = PointBuilder::new(Dimension::XY); /// assert!(builder.is_empty()); /// builder.push_point(Some(&geo::point!(x: 1., y: 2.))); /// assert!(!builder.is_empty()); @@ -844,7 +844,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// ``` /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; /// - /// let builder = PointBuilder::<2>::new(); + /// let builder = PointBuilder::new(Dimension::XY); /// assert!(builder.nulls().is_empty()); /// ``` fn nulls(&self) -> &NullBufferBuilder; @@ -855,7 +855,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// /// ``` /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; - /// let builder = PointBuilder::<2>::new(); + /// let builder = PointBuilder::new(Dimension::XY); /// ``` fn new() -> Self; @@ -915,7 +915,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// array::{PointBuilder, metadata::{ArrayMetadata, Edges}}, /// trait_::GeometryArrayBuilder, /// }; - /// let mut builder = PointBuilder::<2>::new(); + /// let mut builder = PointBuilder::new(Dimension::XY); /// let metadata = ArrayMetadata { /// crs: None, /// edges: Some(Edges::Spherical), @@ -931,7 +931,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// ``` /// use geoarrow::{array::PointBuilder, trait_::{GeometryArrayBuilder, NativeArray, ArrayBase}}; /// - /// let mut builder = PointBuilder::<2>::new(); + /// let mut builder = PointBuilder::new(Dimension::XY); /// builder.push_point(Some(&geo::point!(x: 1., y: 2.))); /// let array = builder.finish(); /// assert_eq!(array.len(), 1); @@ -944,7 +944,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// /// ``` /// use geoarrow::{array::{PointBuilder, CoordType}, trait_::GeometryArrayBuilder}; - /// let builder = PointBuilder::<2>::new(); + /// let builder = PointBuilder::new(Dimension::XY); /// assert_eq!(builder.coord_type(), CoordType::Interleaved); /// ``` fn coord_type(&self) -> CoordType; @@ -955,7 +955,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// /// ``` /// use geoarrow::{array::{PointBuilder, CoordType}, trait_::GeometryArrayBuilder}; - /// let builder = PointBuilder::<2>::new(); + /// let builder = PointBuilder::new(Dimension::XY); /// let metadata = builder.metadata(); /// ``` fn metadata(&self) -> Arc; @@ -980,7 +980,7 @@ pub trait GeometryArrayBuilder: std::fmt::Debug + Send + Sync + Sized { /// /// ``` /// use geoarrow::{array::PointBuilder, trait_::GeometryArrayBuilder}; - /// let builder = PointBuilder::<2>::new(); + /// let builder = PointBuilder::new(Dimension::XY); /// let array_ref = builder.into_array_ref(); /// ``` fn into_array_ref(self) -> Arc;