diff --git a/rust/geoarrow/src/array/binary/array.rs b/rust/geoarrow/src/array/binary/array.rs index 2b732d18..a30d71aa 100644 --- a/rust/geoarrow/src/array/binary/array.rs +++ b/rust/geoarrow/src/array/binary/array.rs @@ -7,14 +7,13 @@ use crate::array::{CoordType, WKBBuilder}; use crate::datatypes::{NativeType, SerializedType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::WKB; -use geo_traits::GeometryTrait; -// use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::trait_::{ArrayAccessor, ArrayBase, IntoArrow, SerializedArray}; use arrow::array::AsArray; use arrow_array::OffsetSizeTrait; use arrow_array::{Array, BinaryArray, GenericBinaryArray, LargeBinaryArray}; use arrow_buffer::NullBuffer; use arrow_schema::{DataType, Field}; +use geo_traits::GeometryTrait; /// An immutable array of WKB geometries using GeoArrow's in-memory representation. /// @@ -94,31 +93,6 @@ impl WKBArray { } } - pub fn owned_slice(&self, _offset: usize, _length: usize) -> Self { - todo!() - // assert!( - // offset + length <= self.len(), - // "offset + length may not exceed length of array" - // ); - // assert!(length >= 1, "length must be at least 1"); - - // // Find the start and end of the ring offsets - // let (start_idx, _) = self.array.offsets().start_end(offset); - // let (_, end_idx) = self.array.offsets().start_end(offset + length - 1); - - // let new_offsets = owned_slice_offsets(self.array.offsets(), offset, length); - - // let mut values = self.array.slice(start_idx, end_idx - start_idx); - - // let validity = owned_slice_validity(self.array.nulls(), offset, length); - - // Self::new(GenericBinaryArray::new( - // new_offsets, - // values.as_slice().to_vec().into(), - // validity, - // )) - } - pub fn with_metadata(&self, metadata: Arc) -> Self { let mut arr = self.clone(); arr.metadata = metadata; diff --git a/rust/geoarrow/src/array/coord/combined/array.rs b/rust/geoarrow/src/array/coord/combined/array.rs index 127896ac..f235bb35 100644 --- a/rust/geoarrow/src/array/coord/combined/array.rs +++ b/rust/geoarrow/src/array/coord/combined/array.rs @@ -37,15 +37,6 @@ impl CoordBuffer { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - match self { - CoordBuffer::Interleaved(cb) => { - CoordBuffer::Interleaved(cb.owned_slice(offset, length)) - } - CoordBuffer::Separated(cb) => CoordBuffer::Separated(cb.owned_slice(offset, length)), - } - } - pub fn coord_type(&self) -> CoordType { match self { CoordBuffer::Interleaved(cb) => cb.coord_type(), diff --git a/rust/geoarrow/src/array/coord/interleaved/array.rs b/rust/geoarrow/src/array/coord/interleaved/array.rs index ac0f3a02..afef10aa 100644 --- a/rust/geoarrow/src/array/coord/interleaved/array.rs +++ b/rust/geoarrow/src/array/coord/interleaved/array.rs @@ -89,11 +89,6 @@ impl InterleavedCoordBuffer { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - let buffer = self.slice(offset, length); - Self::new(buffer.coords.to_vec().into(), self.dim) - } - pub fn into_array_ref(self) -> Arc { Arc::new(self.into_arrow()) } diff --git a/rust/geoarrow/src/array/coord/separated/array.rs b/rust/geoarrow/src/array/coord/separated/array.rs index dde988fa..ea3220f3 100644 --- a/rust/geoarrow/src/array/coord/separated/array.rs +++ b/rust/geoarrow/src/array/coord/separated/array.rs @@ -143,24 +143,6 @@ impl SeparatedCoordBuffer { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - - // Initialize array with existing buffers, then overwrite them - let mut sliced_buffers = self.buffers.clone(); - for (i, buffer) in self.buffers.iter().enumerate() { - sliced_buffers[i] = buffer.slice(offset, length).to_vec().into(); - } - - Self { - buffers: sliced_buffers, - dim: self.dim, - } - } - pub fn storage_type(&self) -> DataType { coord_type_to_data_type(CoordType::Separated, self.dim) } diff --git a/rust/geoarrow/src/array/dynamic.rs b/rust/geoarrow/src/array/dynamic.rs index a7f9c726..a426dc1d 100644 --- a/rust/geoarrow/src/array/dynamic.rs +++ b/rust/geoarrow/src/array/dynamic.rs @@ -133,10 +133,6 @@ impl NativeArray for NativeArrayDyn { fn slice(&self, offset: usize, length: usize) -> Arc { self.0.slice(offset, length) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - self.0.owned_slice(offset, length) - } } impl Display for NativeArrayDyn { diff --git a/rust/geoarrow/src/array/geometry/array.rs b/rust/geoarrow/src/array/geometry/array.rs index f3d81749..8fb3018b 100644 --- a/rust/geoarrow/src/array/geometry/array.rs +++ b/rust/geoarrow/src/array/geometry/array.rs @@ -230,26 +230,6 @@ impl GeometryArraySelfMethods for GeometryArray { GeometryArray::Rect(arr) => GeometryArray::Rect(arr.slice(offset, length)), } } - - fn owned_slice(&self, offset: usize, length: usize) -> Self { - match self { - GeometryArray::Point(arr) => GeometryArray::Point(arr.owned_slice(offset, length)), - GeometryArray::LineString(arr) => { - GeometryArray::LineString(arr.owned_slice(offset, length)) - } - GeometryArray::Polygon(arr) => GeometryArray::Polygon(arr.owned_slice(offset, length)), - GeometryArray::MultiPoint(arr) => { - GeometryArray::MultiPoint(arr.owned_slice(offset, length)) - } - GeometryArray::MultiLineString(arr) => { - GeometryArray::MultiLineString(arr.owned_slice(offset, length)) - } - GeometryArray::MultiPolygon(arr) => { - GeometryArray::MultiPolygon(arr.owned_slice(offset, length)) - } - GeometryArray::Rect(arr) => GeometryArray::Rect(arr.owned_slice(offset, length)), - } - } } impl<'a, O: OffsetSizeTrait> ArrayAccessor<'a> for GeometryArray { diff --git a/rust/geoarrow/src/array/geometrycollection/array.rs b/rust/geoarrow/src/array/geometrycollection/array.rs index 20aa0c72..2445de82 100644 --- a/rust/geoarrow/src/array/geometrycollection/array.rs +++ b/rust/geoarrow/src/array/geometrycollection/array.rs @@ -115,10 +115,6 @@ impl GeometryCollectionArray { } } - pub fn owned_slice(&self, _offset: usize, _length: usize) -> Self { - todo!() - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -204,10 +200,6 @@ impl NativeArray for GeometryCollectionArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for GeometryCollectionArray { diff --git a/rust/geoarrow/src/array/linestring/array.rs b/rust/geoarrow/src/array/linestring/array.rs index 4989fb9d..8c400c17 100644 --- a/rust/geoarrow/src/array/linestring/array.rs +++ b/rust/geoarrow/src/array/linestring/array.rs @@ -14,7 +14,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, LineString}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::{ArrayBase, NativeArray}; use arrow::array::AsArray; use arrow_array::{Array, ArrayRef, GenericListArray, OffsetSizeTrait}; @@ -172,28 +171,6 @@ impl LineStringArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - // Find the start and end of the coord buffer - let (start_coord_idx, _) = self.geom_offsets.start_end(offset); - let (_, end_coord_idx) = self.geom_offsets.start_end(offset + length - 1); - - let geom_offsets = owned_slice_offsets(&self.geom_offsets, offset, length); - - let coords = self - .coords - .owned_slice(start_coord_idx, end_coord_idx - start_coord_idx); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new(coords, geom_offsets, validity, self.metadata()) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -287,10 +264,6 @@ impl NativeArray for LineStringArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for LineStringArray { @@ -586,20 +559,6 @@ mod test { assert_eq!(sliced.get_as_geo(0), Some(ls1())); } - #[test] - fn owned_slice() { - let arr: LineStringArray = (vec![ls0(), ls1()].as_slice(), Dimension::XY).into(); - let sliced = arr.owned_slice(1, 1); - - // assert!( - // !sliced.geom_offsets.buffer().is_sliced(), - // "underlying offsets should not be sliced" - // ); - assert_eq!(arr.len(), 2); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(ls1())); - } - #[test] fn parse_wkb_geoarrow_interleaved_example() { let linestring_arr = example_linestring_interleaved(); diff --git a/rust/geoarrow/src/array/mixed/array.rs b/rust/geoarrow/src/array/mixed/array.rs index 07a81a50..c5397748 100644 --- a/rust/geoarrow/src/array/mixed/array.rs +++ b/rust/geoarrow/src/array/mixed/array.rs @@ -281,10 +281,6 @@ impl MixedGeometryArray { } } - pub fn owned_slice(&self, _offset: usize, _length: usize) -> Self { - todo!() - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -376,10 +372,6 @@ impl NativeArray for MixedGeometryArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for MixedGeometryArray { diff --git a/rust/geoarrow/src/array/multilinestring/array.rs b/rust/geoarrow/src/array/multilinestring/array.rs index cfd591b3..d9ae018e 100644 --- a/rust/geoarrow/src/array/multilinestring/array.rs +++ b/rust/geoarrow/src/array/multilinestring/array.rs @@ -12,7 +12,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiLineString}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::{ArrayBase, NativeArray}; use arrow::array::AsArray; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; @@ -185,43 +184,6 @@ impl MultiLineStringArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - // Find the start and end of the ring offsets - let (start_ring_idx, _) = self.geom_offsets.start_end(offset); - let (_, end_ring_idx) = self.geom_offsets.start_end(offset + length - 1); - - // Find the start and end of the coord buffer - let (start_coord_idx, _) = self.ring_offsets.start_end(start_ring_idx); - let (_, end_coord_idx) = self.ring_offsets.start_end(end_ring_idx - 1); - - // Slice the geom_offsets - let geom_offsets = owned_slice_offsets(&self.geom_offsets, offset, length); - let ring_offsets = owned_slice_offsets( - &self.ring_offsets, - start_ring_idx, - end_ring_idx - start_ring_idx, - ); - let coords = self - .coords - .owned_slice(start_coord_idx, end_coord_idx - start_coord_idx); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new( - coords, - geom_offsets, - ring_offsets, - validity, - self.metadata(), - ) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -307,10 +269,6 @@ impl NativeArray for MultiLineStringArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for MultiLineStringArray { @@ -621,24 +579,6 @@ mod test { assert_eq!(sliced.get_as_geo(0), Some(ml1())); } - #[test] - fn owned_slice() { - let arr: MultiLineStringArray = (vec![ml0(), ml1()].as_slice(), Dimension::XY).into(); - let sliced = arr.owned_slice(1, 1); - - // assert!( - // !sliced.geom_offsets.buffer().is_sliced(), - // "underlying offsets should not be sliced" - // ); - assert_eq!(arr.len(), 2); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(ml1())); - - // // Offset is 0 because it's copied to an owned buffer - // assert_eq!(*sliced.geom_offsets.first(), 0); - // assert_eq!(*sliced.ring_offsets.first(), 0); - } - #[test] fn parse_wkb_geoarrow_interleaved_example() { let geom_arr = example_multilinestring_interleaved(); diff --git a/rust/geoarrow/src/array/multipoint/array.rs b/rust/geoarrow/src/array/multipoint/array.rs index 3d71c6c0..1722470e 100644 --- a/rust/geoarrow/src/array/multipoint/array.rs +++ b/rust/geoarrow/src/array/multipoint/array.rs @@ -13,7 +13,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiPoint}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::{ArrayBase, NativeArray}; use arrow::array::AsArray; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; @@ -168,28 +167,6 @@ impl MultiPointArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - // Find the start and end of the coord buffer - let (start_coord_idx, _) = self.geom_offsets.start_end(offset); - let (_, end_coord_idx) = self.geom_offsets.start_end(offset + length - 1); - - let geom_offsets = owned_slice_offsets(&self.geom_offsets, offset, length); - - let coords = self - .coords - .owned_slice(start_coord_idx, end_coord_idx - start_coord_idx); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new(coords, geom_offsets, validity, self.metadata()) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -274,10 +251,6 @@ impl NativeArray for MultiPointArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for MultiPointArray { @@ -549,20 +522,6 @@ mod test { assert_eq!(sliced.get_as_geo(0), Some(mp1())); } - #[test] - fn owned_slice() { - let arr: MultiPointArray = (vec![mp0(), mp1()].as_slice(), Dimension::XY).into(); - let sliced = arr.owned_slice(1, 1); - - // assert!( - // !sliced.geom_offsets.buffer().is_sliced(), - // "underlying offsets should not be sliced" - // ); - assert_eq!(arr.len(), 2); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(mp1())); - } - #[test] fn parse_wkb_geoarrow_interleaved_example() { let geom_arr = example_multipoint_interleaved(); diff --git a/rust/geoarrow/src/array/multipolygon/array.rs b/rust/geoarrow/src/array/multipolygon/array.rs index 71bb92b7..5390ed2d 100644 --- a/rust/geoarrow/src/array/multipolygon/array.rs +++ b/rust/geoarrow/src/array/multipolygon/array.rs @@ -11,7 +11,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, MultiPolygon}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::{ArrayBase, NativeArray}; use arrow::array::AsArray; use arrow_array::{Array, GenericListArray, OffsetSizeTrait}; @@ -236,53 +235,6 @@ impl MultiPolygonArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - // Find the start and end of the polygon offsets - let (start_polygon_idx, _) = self.geom_offsets.start_end(offset); - let (_, end_polygon_idx) = self.geom_offsets.start_end(offset + length - 1); - - // Find the start and end of the ring offsets - let (start_ring_idx, _) = self.polygon_offsets.start_end(start_polygon_idx); - let (_, end_ring_idx) = self.polygon_offsets.start_end(end_polygon_idx - 1); - - // Find the start and end of the coord buffer - let (start_coord_idx, _) = self.ring_offsets.start_end(start_ring_idx); - let (_, end_coord_idx) = self.ring_offsets.start_end(end_ring_idx - 1); - - // Slice the geom_offsets - let geom_offsets = owned_slice_offsets(&self.geom_offsets, offset, length); - let polygon_offsets = owned_slice_offsets( - &self.polygon_offsets, - start_polygon_idx, - end_polygon_idx - start_polygon_idx, - ); - let ring_offsets = owned_slice_offsets( - &self.ring_offsets, - start_ring_idx, - end_ring_idx - start_ring_idx, - ); - let coords = self - .coords - .owned_slice(start_coord_idx, end_coord_idx - start_coord_idx); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new( - coords, - geom_offsets, - polygon_offsets, - ring_offsets, - validity, - self.metadata(), - ) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -369,10 +321,6 @@ impl NativeArray for MultiPolygonArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for MultiPolygonArray { @@ -710,24 +658,6 @@ mod test { assert_eq!(sliced.get_as_geo(0), Some(mp1())); } - #[test] - fn owned_slice() { - let arr: MultiPolygonArray = (vec![mp0(), mp1()].as_slice(), Dimension::XY).into(); - let sliced = arr.owned_slice(1, 1); - - // assert!( - // !sliced.geom_offsets.buffer().is_sliced(), - // "underlying offsets should not be sliced" - // ); - assert_eq!(arr.len(), 2); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(mp1())); - - // // Offset is 0 because it's copied to an owned buffer - // assert_eq!(*sliced.geom_offsets.first(), 0); - // assert_eq!(*sliced.ring_offsets.first(), 0); - } - #[test] fn parse_wkb_geoarrow_interleaved_example() { let geom_arr = example_multipolygon_interleaved(); diff --git a/rust/geoarrow/src/array/point/array.rs b/rust/geoarrow/src/array/point/array.rs index ad406dc5..24798f80 100644 --- a/rust/geoarrow/src/array/point/array.rs +++ b/rust/geoarrow/src/array/point/array.rs @@ -11,7 +11,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, Point}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::owned_slice_validity; use crate::{ArrayBase, NativeArray}; use arrow_array::{Array, ArrayRef, FixedSizeListArray, OffsetSizeTrait, StructArray}; use geo_traits::PointTrait; @@ -119,20 +118,6 @@ impl PointArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - let coords = self.coords.owned_slice(offset, length); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new(coords, validity, self.metadata()) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -216,10 +201,6 @@ impl NativeArray for PointArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for PointArray { @@ -500,17 +481,6 @@ mod test { assert_eq!(sliced.get_as_geo(0), Some(p1())); } - #[test] - fn owned_slice() { - let points: Vec = vec![p0(), p1(), p2()]; - let point_array: PointArray = (points.as_slice(), Dimension::XY).into(); - let sliced = point_array.owned_slice(1, 1); - - assert_eq!(point_array.len(), 3); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(p1())); - } - #[ignore = "point file is invalid (https://github.com/geoarrow/geoarrow-data/issues/2)"] #[test] fn parse_wkb_geoarrow_interleaved_example() { diff --git a/rust/geoarrow/src/array/polygon/array.rs b/rust/geoarrow/src/array/polygon/array.rs index 47a51f54..a1660c72 100644 --- a/rust/geoarrow/src/array/polygon/array.rs +++ b/rust/geoarrow/src/array/polygon/array.rs @@ -13,7 +13,6 @@ use crate::datatypes::{Dimension, NativeType}; use crate::error::{GeoArrowError, Result}; use crate::scalar::{Geometry, Polygon}; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow, NativeGeometryAccessor}; -use crate::util::{owned_slice_offsets, owned_slice_validity}; use crate::{ArrayBase, NativeArray}; use arrow::array::AsArray; use arrow_array::GenericListArray; @@ -189,43 +188,6 @@ impl PolygonArray { } } - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - assert!( - offset + length <= self.len(), - "offset + length may not exceed length of array" - ); - assert!(length >= 1, "length must be at least 1"); - - // Find the start and end of the ring offsets - let (start_ring_idx, _) = self.geom_offsets.start_end(offset); - let (_, end_ring_idx) = self.geom_offsets.start_end(offset + length - 1); - - // Find the start and end of the coord buffer - let (start_coord_idx, _) = self.ring_offsets.start_end(start_ring_idx); - let (_, end_coord_idx) = self.ring_offsets.start_end(end_ring_idx - 1); - - // Slice the geom_offsets - let geom_offsets = owned_slice_offsets(&self.geom_offsets, offset, length); - let ring_offsets = owned_slice_offsets( - &self.ring_offsets, - start_ring_idx, - end_ring_idx - start_ring_idx, - ); - let coords = self - .coords - .owned_slice(start_coord_idx, end_coord_idx - start_coord_idx); - - let validity = owned_slice_validity(self.nulls(), offset, length); - - Self::new( - coords, - geom_offsets, - ring_offsets, - validity, - self.metadata.clone(), - ) - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -311,10 +273,6 @@ impl NativeArray for PolygonArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for PolygonArray { @@ -665,24 +623,6 @@ mod test { // assert_eq!(*arr.geom_offsets.first(), 1); } - #[test] - fn owned_slice() { - let arr: PolygonArray = (vec![p0(), p1()].as_slice(), Dimension::XY).into(); - let sliced = arr.owned_slice(1, 1); - - // assert!( - // !sliced.geom_offsets.buffer().is_sliced(), - // "underlying offsets should not be sliced" - // ); - assert_eq!(arr.len(), 2); - assert_eq!(sliced.len(), 1); - assert_eq!(sliced.get_as_geo(0), Some(p1())); - - // // Offset is 0 because it's copied to an owned buffer - // assert_eq!(*sliced.geom_offsets.first(), 0); - // assert_eq!(*sliced.ring_offsets.first(), 0); - } - #[test] fn parse_wkb_geoarrow_interleaved_example() { let geom_arr = example_polygon_interleaved(); diff --git a/rust/geoarrow/src/array/rect/array.rs b/rust/geoarrow/src/array/rect/array.rs index 902f5e27..26371cba 100644 --- a/rust/geoarrow/src/array/rect/array.rs +++ b/rust/geoarrow/src/array/rect/array.rs @@ -13,7 +13,6 @@ use crate::datatypes::{rect_fields, Dimension, NativeType}; use crate::error::GeoArrowError; use crate::scalar::Rect; use crate::trait_::{ArrayAccessor, GeometryArraySelfMethods, IntoArrow}; -use crate::util::owned_slice_validity; use crate::{ArrayBase, NativeArray}; use geo_traits::RectTrait; @@ -84,13 +83,6 @@ impl RectArray { metadata: self.metadata(), } } - - pub fn owned_slice(&self, offset: usize, length: usize) -> Self { - let lower = self.lower.owned_slice(offset, length); - let upper = self.upper.owned_slice(offset, length); - let validity = owned_slice_validity(self.nulls(), offset, length); - Self::new(lower, upper, validity, self.metadata()) - } } impl ArrayBase for RectArray { @@ -163,10 +155,6 @@ impl NativeArray for RectArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for RectArray { diff --git a/rust/geoarrow/src/array/unknown/array.rs b/rust/geoarrow/src/array/unknown/array.rs index d30e0f31..fd9592d4 100644 --- a/rust/geoarrow/src/array/unknown/array.rs +++ b/rust/geoarrow/src/array/unknown/array.rs @@ -332,10 +332,6 @@ impl UnknownGeometryArray { } } - pub fn owned_slice(&self, _offset: usize, _length: usize) -> Self { - todo!() - } - pub fn to_coord_type(&self, coord_type: CoordType) -> Self { self.clone().into_coord_type(coord_type) } @@ -433,10 +429,6 @@ impl NativeArray for UnknownGeometryArray { fn slice(&self, offset: usize, length: usize) -> Arc { Arc::new(self.slice(offset, length)) } - - fn owned_slice(&self, offset: usize, length: usize) -> Arc { - Arc::new(self.owned_slice(offset, length)) - } } impl GeometryArraySelfMethods for UnknownGeometryArray { diff --git a/rust/geoarrow/src/array/util.rs b/rust/geoarrow/src/array/util.rs index ad3c0a60..91c79cca 100644 --- a/rust/geoarrow/src/array/util.rs +++ b/rust/geoarrow/src/array/util.rs @@ -45,16 +45,6 @@ pub(crate) fn offsets_buffer_to_i32( Ok(unsafe { OffsetBuffer::new_unchecked(i32_offsets.into()) }) } -/// Returns an iterator with the lengths of the offsets -#[inline] -pub(crate) fn offset_lengths( - offsets: &OffsetBuffer, -) -> impl Iterator + '_ { - offsets - .windows(2) - .map(|w| (w[1] - w[0]).to_usize().unwrap()) -} - /// Offsets utils that I miss from arrow2 pub(crate) trait OffsetBufferUtils { /// Returns the length an array with these offsets would be. diff --git a/rust/geoarrow/src/lib.rs b/rust/geoarrow/src/lib.rs index f728eed8..dd3d937a 100644 --- a/rust/geoarrow/src/lib.rs +++ b/rust/geoarrow/src/lib.rs @@ -76,4 +76,3 @@ pub mod table; #[cfg(test)] pub(crate) mod test; pub mod trait_; -mod util; diff --git a/rust/geoarrow/src/scalar/linestring/scalar.rs b/rust/geoarrow/src/scalar/linestring/scalar.rs index 7c947ed0..b27508ea 100644 --- a/rust/geoarrow/src/scalar/linestring/scalar.rs +++ b/rust/geoarrow/src/scalar/linestring/scalar.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::bounding_rect::bounding_rect_linestring; use crate::algorithm::native::eq::line_string_eq; use crate::array::util::OffsetBufferUtils; -use crate::array::{CoordBuffer, LineStringArray}; +use crate::array::CoordBuffer; use crate::scalar::Coord; use crate::trait_::NativeScalar; use arrow_buffer::OffsetBuffer; @@ -38,15 +38,11 @@ impl<'a> LineString<'a> { } pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { - let arr = LineStringArray::new( + ( self.coords.clone(), self.geom_offsets.clone(), - None, - Default::default(), - ); - let sliced_arr = arr.owned_slice(self.geom_index, 1); - let (coords, geom_offsets, _validity) = sliced_arr.into_inner(); - (coords, geom_offsets, 0) + self.geom_index, + ) } } diff --git a/rust/geoarrow/src/scalar/multilinestring/scalar.rs b/rust/geoarrow/src/scalar/multilinestring/scalar.rs index 2f621f8c..da5b3486 100644 --- a/rust/geoarrow/src/scalar/multilinestring/scalar.rs +++ b/rust/geoarrow/src/scalar/multilinestring/scalar.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::bounding_rect::bounding_rect_multilinestring; use crate::algorithm::native::eq::multi_line_string_eq; use crate::array::util::OffsetBufferUtils; -use crate::array::{CoordBuffer, MultiLineStringArray}; +use crate::array::CoordBuffer; use crate::scalar::LineString; use crate::trait_::NativeScalar; use arrow_buffer::OffsetBuffer; @@ -43,19 +43,11 @@ impl<'a> MultiLineString<'a> { } pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { - let arr = MultiLineStringArray::new( + ( self.coords.clone(), self.geom_offsets.clone(), self.ring_offsets.clone(), - None, - Default::default(), - ); - let sliced_arr = arr.owned_slice(self.geom_index, 1); - ( - sliced_arr.coords, - sliced_arr.geom_offsets, - sliced_arr.ring_offsets, - 0, + self.geom_index, ) } } diff --git a/rust/geoarrow/src/scalar/multipoint/scalar.rs b/rust/geoarrow/src/scalar/multipoint/scalar.rs index cec3ceb9..090fd409 100644 --- a/rust/geoarrow/src/scalar/multipoint/scalar.rs +++ b/rust/geoarrow/src/scalar/multipoint/scalar.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::bounding_rect::bounding_rect_multipoint; use crate::algorithm::native::eq::multi_point_eq; use crate::array::util::OffsetBufferUtils; -use crate::array::{CoordBuffer, MultiPointArray}; +use crate::array::CoordBuffer; use crate::datatypes::Dimension; use crate::scalar::Point; use crate::trait_::NativeScalar; @@ -40,15 +40,11 @@ impl<'a> MultiPoint<'a> { } pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, usize) { - let arr = MultiPointArray::new( + ( self.coords.clone(), self.geom_offsets.clone(), - None, - Default::default(), - ); - let sliced_arr = arr.owned_slice(self.geom_index, 1); - let (coords, geom_offsets, _validity) = sliced_arr.into_inner(); - (coords, geom_offsets, 0) + self.geom_index, + ) } } diff --git a/rust/geoarrow/src/scalar/multipolygon/scalar.rs b/rust/geoarrow/src/scalar/multipolygon/scalar.rs index a802c573..1b2995a9 100644 --- a/rust/geoarrow/src/scalar/multipolygon/scalar.rs +++ b/rust/geoarrow/src/scalar/multipolygon/scalar.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::bounding_rect::bounding_rect_multipolygon; use crate::algorithm::native::eq::multi_polygon_eq; use crate::array::util::OffsetBufferUtils; -use crate::array::{CoordBuffer, MultiPolygonArray}; +use crate::array::CoordBuffer; use crate::datatypes::Dimension; use crate::scalar::Polygon; use crate::trait_::NativeScalar; @@ -57,18 +57,13 @@ impl<'a> MultiPolygon<'a> { OffsetBuffer, usize, ) { - let arr = MultiPolygonArray::new( + ( self.coords.clone(), self.geom_offsets.clone(), self.polygon_offsets.clone(), self.ring_offsets.clone(), - None, - Default::default(), - ); - let sliced_arr = arr.owned_slice(self.geom_index, 1); - let (coords, geom_offsets, polygon_offsets, ring_offsets) = sliced_arr.into_inner(); - - (coords, geom_offsets, polygon_offsets, ring_offsets, 0) + self.geom_index, + ) } } diff --git a/rust/geoarrow/src/scalar/point/scalar.rs b/rust/geoarrow/src/scalar/point/scalar.rs index f4f7d403..2fe4cd7c 100644 --- a/rust/geoarrow/src/scalar/point/scalar.rs +++ b/rust/geoarrow/src/scalar/point/scalar.rs @@ -20,8 +20,7 @@ impl<'a> Point<'a> { } pub fn into_owned_inner(self) -> (CoordBuffer, usize) { - let coords = self.coords.owned_slice(self.geom_index, 1); - (coords, self.geom_index) + (self.coords.clone(), self.geom_index) } } diff --git a/rust/geoarrow/src/scalar/polygon/scalar.rs b/rust/geoarrow/src/scalar/polygon/scalar.rs index ef8db9ad..ec47f02b 100644 --- a/rust/geoarrow/src/scalar/polygon/scalar.rs +++ b/rust/geoarrow/src/scalar/polygon/scalar.rs @@ -1,7 +1,7 @@ use crate::algorithm::native::bounding_rect::bounding_rect_polygon; use crate::algorithm::native::eq::polygon_eq; use crate::array::util::OffsetBufferUtils; -use crate::array::{CoordBuffer, PolygonArray}; +use crate::array::CoordBuffer; use crate::datatypes::Dimension; use crate::scalar::LineString; use crate::trait_::NativeScalar; @@ -44,20 +44,11 @@ impl<'a> Polygon<'a> { } pub fn into_owned_inner(self) -> (CoordBuffer, OffsetBuffer, OffsetBuffer, usize) { - let arr = PolygonArray::new( + ( self.coords.clone(), self.geom_offsets.clone(), self.ring_offsets.clone(), - None, - Default::default(), - ); - let sliced_arr = arr.owned_slice(self.geom_index, 1); - - ( - sliced_arr.coords, - sliced_arr.geom_offsets, - sliced_arr.ring_offsets, - 0, + self.geom_index, ) } } diff --git a/rust/geoarrow/src/trait_.rs b/rust/geoarrow/src/trait_.rs index e0b1aeb1..ca9303e1 100644 --- a/rust/geoarrow/src/trait_.rs +++ b/rust/geoarrow/src/trait_.rs @@ -359,22 +359,6 @@ pub trait NativeArray: ArrayBase { /// This function panics iff `offset + length > self.len()`. #[must_use] fn slice(&self, offset: usize, length: usize) -> Arc; - - /// Returns a owned slice that fully copies the contents of the underlying buffer. - /// - /// # Examples - /// - /// ``` - /// use geoarrow::{array::PointArray, trait_::GeometryArraySelfMethods}; - /// use geoarrow::datatypes::Dimension; - /// - /// let point_0 = geo::point!(x: 1., y: 2.); - /// let point_1 = geo::point!(x: 3., y: 4.); - /// let array: PointArray = (vec![point_0, point_1].as_slice(), Dimension::XY).into(); - /// let smaller_array = array.owned_slice(1, 1); - /// ``` - #[must_use] - fn owned_slice(&self, offset: usize, length: usize) -> Arc; } /// Type alias for a dynamic reference to something that implements [NativeArray]. diff --git a/rust/geoarrow/src/util.rs b/rust/geoarrow/src/util.rs deleted file mode 100644 index 886cb00d..00000000 --- a/rust/geoarrow/src/util.rs +++ /dev/null @@ -1,42 +0,0 @@ -use arrow_array::OffsetSizeTrait; -use arrow_buffer::{NullBuffer, NullBufferBuilder, OffsetBuffer}; - -use crate::array::offset_builder::OffsetsBuilder; -use crate::array::util::offset_lengths; - -pub(crate) fn owned_slice_offsets( - offsets: &OffsetBuffer, - offset: usize, - length: usize, -) -> OffsetBuffer { - // TODO: double check but now that we've moved to arrow-rs it looks like this slice adds 1 for - // us. - let sliced_offsets = offsets.slice(offset, length); - - let mut new_offsets: OffsetsBuilder = OffsetsBuilder::with_capacity(length); - - for item in offset_lengths(&sliced_offsets) { - new_offsets.try_push_usize(item).unwrap(); - } - - new_offsets.into() -} - -pub(crate) fn owned_slice_validity( - validity: Option<&NullBuffer>, - offset: usize, - length: usize, -) -> Option { - if let Some(validity) = validity { - let sliced_validity = validity.slice(offset, length); - - let mut new_bitmap = NullBufferBuilder::new(length); - for value in sliced_validity.into_iter() { - new_bitmap.append(value); - } - - new_bitmap.finish() - } else { - None - } -}