Skip to content

Commit 4b58f40

Browse files
authored
geoarrow-array API cleanup (#1131)
- Remove `into_inner` that was only implemented on a few geometry array types - Remove `from_geometries` in favor of `from_nullable_geometries` on geometry builders - Remove `reserve_from_iter`. Use `reserve` instead with a capacity counter - Remove `with_capacity_from_iter` in favor of the user calling `with_capacity` manually - Slim down API for adding geometries into Geometry and WKB capacity counters - Use GAT types in `GeometryType::as_type`
1 parent e075dd5 commit 4b58f40

19 files changed

+88
-510
lines changed

rust/geoarrow-array/src/array/geometry.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,9 +1053,9 @@ mod test {
10531053
}
10541054

10551055
fn geom_array(coord_type: CoordType) -> GeometryArray {
1056-
let geoms = geoms();
1056+
let geoms = geoms().into_iter().map(Some).collect::<Vec<_>>();
10571057
let typ = GeometryType::new(coord_type, Default::default());
1058-
GeometryBuilder::from_geometries(&geoms, typ)
1058+
GeometryBuilder::from_nullable_geometries(&geoms, typ)
10591059
.unwrap()
10601060
.finish()
10611061
}

rust/geoarrow-array/src/array/point.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ impl PointArray {
8181
&self.coords
8282
}
8383

84-
/// Access the
85-
pub fn into_inner(self) -> (CoordBuffer, Option<NullBuffer>) {
86-
(self.coords, self.nulls)
87-
}
88-
8984
/// The lengths of each buffer contained in this array.
9085
pub fn buffer_lengths(&self) -> usize {
9186
self.len()

rust/geoarrow-array/src/array/wkt.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@ impl<O: OffsetSizeTrait> GenericWktArray<O> {
5050
&self.array
5151
}
5252

53-
/// Consume self and access the underlying data.
54-
pub fn into_inner(self) -> GenericStringArray<O> {
55-
self.array
56-
}
57-
5853
/// Slices this [`GenericWkbArray`] in place.
5954
/// # Panic
6055
/// This function panics iff `offset + length > self.len()`.

rust/geoarrow-array/src/builder/geometry.rs

Lines changed: 2 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use geoarrow_schema::{
66
Dimension, GeometryCollectionType, GeometryType, LineStringType, Metadata, MultiLineStringType,
77
MultiPointType, MultiPolygonType, PointType, PolygonType,
88
};
9-
use wkt::WktNum;
109

1110
use crate::GeoArrowArray;
1211
use crate::array::{DimensionIndex, GenericWkbArray, GeometryArray};
@@ -296,37 +295,6 @@ impl<'a> GeometryBuilder {
296295
)
297296
}
298297

299-
/// Creates a new builder with a capacity inferred by the provided iterator.
300-
pub fn with_capacity_from_iter<T: WktNum>(
301-
geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = T> + 'a)>>,
302-
typ: GeometryType,
303-
) -> Result<Self> {
304-
let counter = GeometryCapacity::from_geometries(geoms)?;
305-
Ok(Self::with_capacity(typ, counter))
306-
}
307-
308-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
309-
/// geometries.
310-
pub fn reserve_from_iter<T: WktNum>(
311-
&mut self,
312-
geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = T> + 'a)>>,
313-
) -> Result<()> {
314-
let counter = GeometryCapacity::from_geometries(geoms)?;
315-
self.reserve(counter);
316-
Ok(())
317-
}
318-
319-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
320-
/// geometries.
321-
pub fn reserve_exact_from_iter<T: WktNum>(
322-
&mut self,
323-
geoms: impl Iterator<Item = Option<&'a (impl GeometryTrait<T = T> + 'a)>>,
324-
) -> Result<()> {
325-
let counter = GeometryCapacity::from_geometries(geoms)?;
326-
self.reserve_exact(counter);
327-
Ok(())
328-
}
329-
330298
/// Add a new Point to the end of this array.
331299
///
332300
/// If `self.prefer_multi` is `true`, it will be stored in the `MultiPointBuilder` child
@@ -788,22 +756,13 @@ impl<'a> GeometryBuilder {
788756
.unwrap();
789757
}
790758

791-
/// Create this builder from a slice of Geometries.
792-
pub fn from_geometries(
793-
geoms: &[impl GeometryTrait<T = f64>],
794-
typ: GeometryType,
795-
) -> Result<Self> {
796-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(Some), typ)?;
797-
array.extend_from_iter(geoms.iter().map(Some));
798-
Ok(array)
799-
}
800-
801759
/// Create this builder from a slice of nullable Geometries.
802760
pub fn from_nullable_geometries(
803761
geoms: &[Option<impl GeometryTrait<T = f64>>],
804762
typ: GeometryType,
805763
) -> Result<Self> {
806-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(|x| x.as_ref()), typ)?;
764+
let capacity = GeometryCapacity::from_geometries(geoms.iter().map(|x| x.as_ref()))?;
765+
let mut array = Self::with_capacity(typ, capacity);
807766
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
808767
Ok(array)
809768
}

rust/geoarrow-array/src/builder/geometrycollection.rs

Lines changed: 9 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use geo_traits::{
77
MultiPolygonTrait, PointTrait, PolygonTrait,
88
};
99
use geoarrow_schema::GeometryCollectionType;
10-
use wkt::WktNum;
1110

1211
use crate::GeoArrowArray;
1312
use crate::array::{GenericWkbArray, GeometryCollectionArray};
@@ -38,7 +37,8 @@ impl<'a> GeometryCollectionBuilder {
3837
Self::with_capacity(typ, Default::default())
3938
}
4039

41-
/// Creates a new empty [`GeometryCollectionBuilder`] with the provided capacity.
40+
/// Creates a new empty [`GeometryCollectionBuilder`] with the provided
41+
/// [capacity][GeometryCollectionCapacity].
4242
pub fn with_capacity(
4343
typ: GeometryCollectionType,
4444
capacity: GeometryCollectionCapacity,
@@ -110,38 +110,6 @@ impl<'a> GeometryCollectionBuilder {
110110
)
111111
}
112112

113-
/// Creates a new [`GeometryCollectionBuilder`] with a capacity inferred by the provided
114-
/// iterator.
115-
pub fn with_capacity_from_iter<T: WktNum>(
116-
geoms: impl Iterator<Item = Option<&'a (impl GeometryCollectionTrait<T = T> + 'a)>>,
117-
typ: GeometryCollectionType,
118-
) -> Result<Self> {
119-
let counter = GeometryCollectionCapacity::from_geometry_collections(geoms)?;
120-
Ok(Self::with_capacity(typ, counter))
121-
}
122-
123-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
124-
/// geometries.
125-
pub fn reserve_from_iter<T: WktNum>(
126-
&mut self,
127-
geoms: impl Iterator<Item = Option<&'a (impl GeometryCollectionTrait<T = T> + 'a)>>,
128-
) -> Result<()> {
129-
let counter = GeometryCollectionCapacity::from_geometry_collections(geoms)?;
130-
self.reserve(counter);
131-
Ok(())
132-
}
133-
134-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
135-
/// geometries.
136-
pub fn reserve_exact_from_iter<T: WktNum>(
137-
&mut self,
138-
geoms: impl Iterator<Item = Option<&'a (impl GeometryCollectionTrait<T = T> + 'a)>>,
139-
) -> Result<()> {
140-
let counter = GeometryCollectionCapacity::from_geometry_collections(geoms)?;
141-
self.reserve_exact(counter);
142-
Ok(())
143-
}
144-
145113
/// Push a Point onto the end of this builder
146114
#[inline]
147115
fn push_point(&mut self, value: Option<&impl PointTrait<T = f64>>) -> Result<()> {
@@ -299,7 +267,9 @@ impl<'a> GeometryCollectionBuilder {
299267
geoms: &[impl GeometryCollectionTrait<T = f64>],
300268
typ: GeometryCollectionType,
301269
) -> Result<Self> {
302-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(Some), typ)?;
270+
let capacity =
271+
GeometryCollectionCapacity::from_geometry_collections(geoms.iter().map(Some))?;
272+
let mut array = Self::with_capacity(typ, capacity);
303273
array.extend_from_iter(geoms.iter().map(Some));
304274
Ok(array)
305275
}
@@ -309,21 +279,11 @@ impl<'a> GeometryCollectionBuilder {
309279
geoms: &[Option<impl GeometryCollectionTrait<T = f64>>],
310280
typ: GeometryCollectionType,
311281
) -> Result<Self> {
312-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(|x| x.as_ref()), typ)?;
313-
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
314-
Ok(array)
315-
}
316-
317-
/// Construct a new builder, pre-filling it with the provided geometries
318-
pub fn from_geometries(
319-
geoms: &[impl GeometryTrait<T = f64>],
320-
typ: GeometryCollectionType,
321-
) -> Result<Self> {
322-
let capacity = GeometryCollectionCapacity::from_geometries(geoms.iter().map(Some))?;
282+
let capacity = GeometryCollectionCapacity::from_geometry_collections(
283+
geoms.iter().map(|x| x.as_ref()),
284+
)?;
323285
let mut array = Self::with_capacity(typ, capacity);
324-
for geom in geoms {
325-
array.push_geometry(Some(geom))?;
326-
}
286+
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
327287
Ok(array)
328288
}
329289

rust/geoarrow-array/src/builder/linestring.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -121,38 +121,10 @@ impl LineStringBuilder {
121121
)
122122
}
123123

124-
/// Creates a new builder with a capacity inferred by the provided iterator.
125-
pub fn with_capacity_from_iter<'a>(
126-
typ: LineStringType,
127-
geoms: impl Iterator<Item = Option<&'a (impl LineStringTrait + 'a)>>,
128-
) -> Self {
129-
let counter = LineStringCapacity::from_line_strings(geoms);
130-
Self::with_capacity(typ, counter)
131-
}
132-
133-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
134-
/// geometries.
135-
pub fn reserve_from_iter<'a>(
136-
&mut self,
137-
geoms: impl Iterator<Item = Option<&'a (impl LineStringTrait + 'a)>>,
138-
) {
139-
let counter = LineStringCapacity::from_line_strings(geoms);
140-
self.reserve(counter)
141-
}
142-
143-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
144-
/// geometries.
145-
pub fn reserve_exact_from_iter<'a>(
146-
&mut self,
147-
geoms: impl Iterator<Item = Option<&'a (impl LineStringTrait + 'a)>>,
148-
) {
149-
let counter = LineStringCapacity::from_line_strings(geoms);
150-
self.reserve_exact(counter)
151-
}
152-
153124
/// Construct a new builder, pre-filling it with the provided geometries
154125
pub fn from_line_strings(geoms: &[impl LineStringTrait<T = f64>], typ: LineStringType) -> Self {
155-
let mut array = Self::with_capacity_from_iter(typ, geoms.iter().map(Some));
126+
let capacity = LineStringCapacity::from_line_strings(geoms.iter().map(Some));
127+
let mut array = Self::with_capacity(typ, capacity);
156128
array.extend_from_iter(geoms.iter().map(Some));
157129
array
158130
}
@@ -162,7 +134,8 @@ impl LineStringBuilder {
162134
geoms: &[Option<impl LineStringTrait<T = f64>>],
163135
typ: LineStringType,
164136
) -> Self {
165-
let mut array = Self::with_capacity_from_iter(typ, geoms.iter().map(|x| x.as_ref()));
137+
let capacity = LineStringCapacity::from_line_strings(geoms.iter().map(|x| x.as_ref()));
138+
let mut array = Self::with_capacity(typ, capacity);
166139
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
167140
array
168141
}

rust/geoarrow-array/src/builder/multilinestring.rs

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -166,35 +166,6 @@ impl MultiLineStringBuilder {
166166
)
167167
}
168168

169-
/// Creates a new builder with a capacity inferred by the provided iterator.
170-
pub fn with_capacity_from_iter<'a>(
171-
geoms: impl Iterator<Item = Option<&'a (impl MultiLineStringTrait + 'a)>>,
172-
typ: MultiLineStringType,
173-
) -> Self {
174-
let counter = MultiLineStringCapacity::from_multi_line_strings(geoms);
175-
Self::with_capacity(typ, counter)
176-
}
177-
178-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
179-
/// geometries.
180-
pub fn reserve_from_iter<'a>(
181-
&mut self,
182-
geoms: impl Iterator<Item = Option<&'a (impl MultiLineStringTrait + 'a)>>,
183-
) {
184-
let counter = MultiLineStringCapacity::from_multi_line_strings(geoms);
185-
self.reserve(counter)
186-
}
187-
188-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
189-
/// geometries.
190-
pub fn reserve_exact_from_iter<'a>(
191-
&mut self,
192-
geoms: impl Iterator<Item = Option<&'a (impl MultiLineStringTrait + 'a)>>,
193-
) {
194-
let counter = MultiLineStringCapacity::from_multi_line_strings(geoms);
195-
self.reserve_exact(counter)
196-
}
197-
198169
/// Add a new LineString to the end of this array.
199170
///
200171
/// # Errors
@@ -330,7 +301,8 @@ impl MultiLineStringBuilder {
330301
geoms: &[impl MultiLineStringTrait<T = f64>],
331302
typ: MultiLineStringType,
332303
) -> Self {
333-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(Some), typ);
304+
let capacity = MultiLineStringCapacity::from_multi_line_strings(geoms.iter().map(Some));
305+
let mut array = Self::with_capacity(typ, capacity);
334306
array.extend_from_iter(geoms.iter().map(Some));
335307
array
336308
}
@@ -340,7 +312,9 @@ impl MultiLineStringBuilder {
340312
geoms: &[Option<impl MultiLineStringTrait<T = f64>>],
341313
typ: MultiLineStringType,
342314
) -> Self {
343-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(|x| x.as_ref()), typ);
315+
let capacity =
316+
MultiLineStringCapacity::from_multi_line_strings(geoms.iter().map(|x| x.as_ref()));
317+
let mut array = Self::with_capacity(typ, capacity);
344318
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
345319
array
346320
}

rust/geoarrow-array/src/builder/multipoint.rs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -102,35 +102,6 @@ impl MultiPointBuilder {
102102
)
103103
}
104104

105-
/// Creates a new builder with a capacity inferred by the provided iterator.
106-
pub fn with_capacity_from_iter<'a>(
107-
geoms: impl Iterator<Item = Option<&'a (impl MultiPointTrait + 'a)>>,
108-
typ: MultiPointType,
109-
) -> Self {
110-
let counter = MultiPointCapacity::from_multi_points(geoms);
111-
Self::with_capacity(typ, counter)
112-
}
113-
114-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
115-
/// geometries.
116-
pub fn reserve_from_iter<'a>(
117-
&mut self,
118-
geoms: impl Iterator<Item = Option<&'a (impl MultiPointTrait + 'a)>>,
119-
) {
120-
let counter = MultiPointCapacity::from_multi_points(geoms);
121-
self.reserve(counter)
122-
}
123-
124-
/// Reserve more space in the underlying buffers with the capacity inferred from the provided
125-
/// geometries.
126-
pub fn reserve_exact_from_iter<'a>(
127-
&mut self,
128-
geoms: impl Iterator<Item = Option<&'a (impl MultiPointTrait + 'a)>>,
129-
) {
130-
let counter = MultiPointCapacity::from_multi_points(geoms);
131-
self.reserve_exact(counter)
132-
}
133-
134105
/// Extend this builder with the given geometries
135106
pub fn extend_from_iter<'a>(
136107
&mut self,
@@ -235,7 +206,8 @@ impl MultiPointBuilder {
235206

236207
/// Construct a new builder, pre-filling it with the provided geometries
237208
pub fn from_multi_points(geoms: &[impl MultiPointTrait<T = f64>], typ: MultiPointType) -> Self {
238-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(Some), typ);
209+
let capacity = MultiPointCapacity::from_multi_points(geoms.iter().map(Some));
210+
let mut array = Self::with_capacity(typ, capacity);
239211
array.extend_from_iter(geoms.iter().map(Some));
240212
array
241213
}
@@ -245,7 +217,8 @@ impl MultiPointBuilder {
245217
geoms: &[Option<impl MultiPointTrait<T = f64>>],
246218
typ: MultiPointType,
247219
) -> Self {
248-
let mut array = Self::with_capacity_from_iter(geoms.iter().map(|x| x.as_ref()), typ);
220+
let capacity = MultiPointCapacity::from_multi_points(geoms.iter().map(|x| x.as_ref()));
221+
let mut array = Self::with_capacity(typ, capacity);
249222
array.extend_from_iter(geoms.iter().map(|x| x.as_ref()));
250223
array
251224
}

0 commit comments

Comments
 (0)