Skip to content

Commit 5b00fe0

Browse files
committed
Coord buffer refactor
1 parent 8fda9ab commit 5b00fe0

File tree

37 files changed

+722
-356
lines changed

37 files changed

+722
-356
lines changed

rust/geoarrow/benches/geos_buffer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
use criterion::{criterion_group, criterion_main, Criterion};
22
use geoarrow::algorithm::geos::Buffer;
33
use geoarrow::array::{CoordBuffer, InterleavedCoordBuffer, PointArray, PolygonArray};
4+
use geoarrow::datatypes::Dimension;
45

56
fn generate_data() -> PointArray<2> {
67
let coords = vec![0.0; 100_000];
7-
let coord_buffer = CoordBuffer::Interleaved(InterleavedCoordBuffer::new(coords.into()));
8+
let coord_buffer = CoordBuffer::new_interleaved(coords.into(), Dimension::XY).unwrap();
89
PointArray::new(coord_buffer, None, Default::default())
910
}
1011

rust/geoarrow/src/algorithm/native/downcast.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ impl Downcast for MultiPointArray<2> {
144144
fn downcast(&self, small_offsets: bool) -> Self::Output {
145145
// Note: this won't allow a downcast for empty MultiPoints
146146
if *self.geom_offsets.last() as usize == self.len() {
147-
return Arc::new(PointArray::new(
147+
return Arc::new(PointArray::<2>::new(
148148
self.coords.clone(),
149149
self.validity.clone(),
150150
self.metadata(),
@@ -173,7 +173,7 @@ impl Downcast for MultiLineStringArray<2> {
173173

174174
fn downcast(&self, small_offsets: bool) -> Self::Output {
175175
if *self.geom_offsets.last() as usize == self.len() {
176-
return Arc::new(LineStringArray::new(
176+
return Arc::new(LineStringArray::<2>::new(
177177
self.coords.clone(),
178178
self.ring_offsets.clone(),
179179
self.validity.clone(),
@@ -203,7 +203,7 @@ impl Downcast for MultiPolygonArray<2> {
203203

204204
fn downcast(&self, small_offsets: bool) -> Self::Output {
205205
if *self.geom_offsets.last() as usize == self.len() {
206-
return Arc::new(PolygonArray::new(
206+
return Arc::new(PolygonArray::<2>::new(
207207
self.coords.clone(),
208208
self.polygon_offsets.clone(),
209209
self.ring_offsets.clone(),

rust/geoarrow/src/algorithm/native/map_coords.rs

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,25 @@ pub trait MapCoords {
1818

1919
fn map_coords<F>(&self, map_op: F) -> Result<Self::Output>
2020
where
21-
F: Fn(&crate::scalar::Coord<2>) -> geo::Coord + Sync,
21+
F: Fn(&crate::scalar::Coord) -> geo::Coord + Sync,
2222
{
2323
self.try_map_coords(|coord| Ok::<_, GeoArrowError>(map_op(coord)))
2424
}
2525

2626
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
2727
where
28-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
28+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
2929
GeoArrowError: From<E>;
3030
}
3131

3232
// Scalar impls
3333

34-
impl MapCoords for Coord<'_, 2> {
34+
impl MapCoords for Coord<'_> {
3535
type Output = geo::Coord;
3636

3737
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
3838
where
39-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
39+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
4040
GeoArrowError: From<E>,
4141
{
4242
Ok(map_op(self)?)
@@ -48,7 +48,7 @@ impl MapCoords for Point<'_, 2> {
4848

4949
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
5050
where
51-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
51+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
5252
GeoArrowError: From<E>,
5353
{
5454
Ok(geo::Point(map_op(&self.coord())?))
@@ -60,7 +60,7 @@ impl MapCoords for LineString<'_, 2> {
6060

6161
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
6262
where
63-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
63+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
6464
GeoArrowError: From<E>,
6565
{
6666
let output_coords = self
@@ -76,7 +76,7 @@ impl MapCoords for Polygon<'_, 2> {
7676

7777
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
7878
where
79-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
79+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
8080
GeoArrowError: From<E>,
8181
{
8282
if self.exterior().is_none() {
@@ -98,7 +98,7 @@ impl MapCoords for MultiPoint<'_, 2> {
9898

9999
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
100100
where
101-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
101+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
102102
GeoArrowError: From<E>,
103103
{
104104
let points = self
@@ -114,7 +114,7 @@ impl MapCoords for MultiLineString<'_, 2> {
114114

115115
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
116116
where
117-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
117+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
118118
GeoArrowError: From<E>,
119119
{
120120
let lines = self
@@ -131,7 +131,7 @@ impl MapCoords for MultiPolygon<'_, 2> {
131131

132132
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
133133
where
134-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
134+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
135135
GeoArrowError: From<E>,
136136
{
137137
let polygons = self
@@ -147,7 +147,7 @@ impl MapCoords for Geometry<'_, 2> {
147147

148148
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
149149
where
150-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
150+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
151151
GeoArrowError: From<E>,
152152
{
153153
use GeometryType::*;
@@ -175,7 +175,7 @@ impl MapCoords for GeometryCollection<'_, 2> {
175175

176176
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
177177
where
178-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
178+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
179179
GeoArrowError: From<E>,
180180
{
181181
let geoms = self
@@ -191,7 +191,7 @@ impl MapCoords for Rect<'_, 2> {
191191

192192
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
193193
where
194-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
194+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
195195
GeoArrowError: From<E>,
196196
{
197197
let lower = self.min();
@@ -201,7 +201,7 @@ impl MapCoords for Rect<'_, 2> {
201201
let maxx = upper.x();
202202
let maxy = upper.y();
203203
let coords = vec![minx, miny, maxx, maxy];
204-
let coord_buffer = CoordBuffer::Interleaved(InterleavedCoordBuffer::new(coords.into()));
204+
let coord_buffer = CoordBuffer::new_interleaved(coords.into(), Dimension::XY).unwrap();
205205
let lower_coord = coord_buffer.value(0);
206206
let upper_coord = coord_buffer.value(1);
207207

@@ -216,7 +216,7 @@ impl MapCoords for PointArray<2> {
216216

217217
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
218218
where
219-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
219+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
220220
GeoArrowError: From<E>,
221221
{
222222
let mut builder = PointBuilder::with_capacity_and_options(
@@ -241,7 +241,7 @@ impl MapCoords for LineStringArray<2> {
241241

242242
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
243243
where
244-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
244+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
245245
GeoArrowError: From<E>,
246246
{
247247
let mut builder = LineStringBuilder::with_capacity_and_options(
@@ -266,7 +266,7 @@ impl MapCoords for PolygonArray<2> {
266266

267267
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
268268
where
269-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
269+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
270270
GeoArrowError: From<E>,
271271
{
272272
let mut builder = PolygonBuilder::with_capacity_and_options(
@@ -291,7 +291,7 @@ impl MapCoords for MultiPointArray<2> {
291291

292292
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
293293
where
294-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
294+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
295295
GeoArrowError: From<E>,
296296
{
297297
let mut builder = MultiPointBuilder::with_capacity_and_options(
@@ -316,7 +316,7 @@ impl MapCoords for MultiLineStringArray<2> {
316316

317317
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
318318
where
319-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
319+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
320320
GeoArrowError: From<E>,
321321
{
322322
let mut builder = MultiLineStringBuilder::with_capacity_and_options(
@@ -341,7 +341,7 @@ impl MapCoords for MultiPolygonArray<2> {
341341

342342
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
343343
where
344-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
344+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
345345
GeoArrowError: From<E>,
346346
{
347347
let mut builder = MultiPolygonBuilder::with_capacity_and_options(
@@ -366,7 +366,7 @@ impl MapCoords for MixedGeometryArray<2> {
366366

367367
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
368368
where
369-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
369+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
370370
GeoArrowError: From<E>,
371371
{
372372
let mut builder = MixedGeometryBuilder::with_capacity_and_options(
@@ -392,7 +392,7 @@ impl MapCoords for GeometryCollectionArray<2> {
392392

393393
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
394394
where
395-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
395+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
396396
GeoArrowError: From<E>,
397397
{
398398
let mut builder = GeometryCollectionBuilder::with_capacity_and_options(
@@ -418,7 +418,7 @@ impl MapCoords for RectArray<2> {
418418

419419
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
420420
where
421-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
421+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
422422
GeoArrowError: From<E>,
423423
{
424424
let mut builder = RectBuilder::with_capacity_and_options(self.len(), self.metadata());
@@ -439,7 +439,7 @@ impl MapCoords for &dyn NativeArray {
439439

440440
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
441441
where
442-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
442+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
443443
GeoArrowError: From<E>,
444444
{
445445
use Dimension::*;
@@ -470,7 +470,7 @@ impl MapCoords for ChunkedPointArray<2> {
470470

471471
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
472472
where
473-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
473+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
474474
GeoArrowError: From<E>,
475475
{
476476
Ok(ChunkedGeometryArray::new(
@@ -484,7 +484,7 @@ impl MapCoords for ChunkedLineStringArray<2> {
484484

485485
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
486486
where
487-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
487+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
488488
GeoArrowError: From<E>,
489489
{
490490
Ok(ChunkedGeometryArray::new(
@@ -498,7 +498,7 @@ impl MapCoords for ChunkedPolygonArray<2> {
498498

499499
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
500500
where
501-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
501+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
502502
GeoArrowError: From<E>,
503503
{
504504
Ok(ChunkedGeometryArray::new(
@@ -512,7 +512,7 @@ impl MapCoords for ChunkedMultiPointArray<2> {
512512

513513
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
514514
where
515-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
515+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
516516
GeoArrowError: From<E>,
517517
{
518518
Ok(ChunkedGeometryArray::new(
@@ -526,7 +526,7 @@ impl MapCoords for ChunkedMultiLineStringArray<2> {
526526

527527
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
528528
where
529-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
529+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
530530
GeoArrowError: From<E>,
531531
{
532532
Ok(ChunkedGeometryArray::new(
@@ -540,7 +540,7 @@ impl MapCoords for ChunkedMultiPolygonArray<2> {
540540

541541
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
542542
where
543-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
543+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
544544
GeoArrowError: From<E>,
545545
{
546546
Ok(ChunkedGeometryArray::new(
@@ -554,7 +554,7 @@ impl MapCoords for ChunkedMixedGeometryArray<2> {
554554

555555
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
556556
where
557-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
557+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
558558
GeoArrowError: From<E>,
559559
{
560560
Ok(ChunkedGeometryArray::new(
@@ -568,7 +568,7 @@ impl MapCoords for ChunkedGeometryCollectionArray<2> {
568568

569569
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
570570
where
571-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
571+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
572572
GeoArrowError: From<E>,
573573
{
574574
Ok(ChunkedGeometryArray::new(
@@ -582,7 +582,7 @@ impl MapCoords for ChunkedRectArray<2> {
582582

583583
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
584584
where
585-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
585+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
586586
GeoArrowError: From<E>,
587587
{
588588
Ok(ChunkedGeometryArray::new(
@@ -596,7 +596,7 @@ impl MapCoords for &dyn ChunkedNativeArray {
596596

597597
fn try_map_coords<F, E>(&self, map_op: F) -> Result<Self::Output>
598598
where
599-
F: Fn(&crate::scalar::Coord<2>) -> std::result::Result<geo::Coord, E> + Sync,
599+
F: Fn(&crate::scalar::Coord) -> std::result::Result<geo::Coord, E> + Sync,
600600
GeoArrowError: From<E>,
601601
{
602602
use Dimension::*;

0 commit comments

Comments
 (0)