-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement conversions from GEOS objects to GeoArrow arrays (#202)
* Implement conversion from geos linestrings to geoarrow * Point and Linestring geos scalar types, wrapped by traits * Attempt at geosmultipoint * Implement geos MultiPoint conversion natively * add point, multipoint, linestring geos round trip tests * polygon geos round trip * bumpalo geos polygon * multipolygon from geos * add test * Add quick geos buffer benchmark
- Loading branch information
1 parent
8d4d4b4
commit 527e003
Showing
40 changed files
with
1,516 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use geoarrow2::algorithm::geos::buffer::Buffer; | ||
use geoarrow2::array::{CoordBuffer, InterleavedCoordBuffer, PointArray}; | ||
|
||
fn generate_data() -> PointArray { | ||
let coords = vec![0.0; 100_000]; | ||
let coord_buffer = CoordBuffer::Interleaved(InterleavedCoordBuffer::new(coords.into())); | ||
PointArray::new(coord_buffer, None) | ||
} | ||
|
||
pub fn criterion_benchmark(c: &mut Criterion) { | ||
let point_array = generate_data(); | ||
|
||
c.bench_function("buffer", |b| { | ||
b.iter(|| { | ||
let _buffered = point_array.buffer(1.0, 8).unwrap(); | ||
}) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, criterion_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
use crate::array::{PointArray, PolygonArray}; | ||
use crate::error::Result; | ||
use crate::GeometryArrayTrait; | ||
use geos::Geom; | ||
|
||
pub trait Buffer { | ||
type Output; | ||
|
||
fn buffer(&self, width: f64, quadsegs: i32) -> Result<Self::Output>; | ||
} | ||
|
||
impl Buffer for PointArray { | ||
type Output = PolygonArray<i32>; | ||
|
||
fn buffer(&self, width: f64, quadsegs: i32) -> Result<Self::Output> { | ||
// NOTE: the bumpalo allocator didn't appear to make any perf difference with geos :shrug: | ||
// Presumably GEOS is allocating on its own before we can put the geometry in the Bump? | ||
let bump = bumpalo::Bump::new(); | ||
|
||
let mut geos_geoms = bumpalo::collections::Vec::with_capacity_in(self.len(), &bump); | ||
|
||
for maybe_g in self.iter_geos() { | ||
if let Some(g) = maybe_g { | ||
let area = g.buffer(width, quadsegs)?; | ||
geos_geoms.push(Some(area)); | ||
} else { | ||
geos_geoms.push(None); | ||
} | ||
} | ||
|
||
let polygon_array: PolygonArray<i32> = geos_geoms.try_into()?; | ||
Ok(polygon_array) | ||
} | ||
} | ||
|
||
// // Note: this can't (easily) be parameterized in the macro because PointArray is not generic over O | ||
// impl Area for PointArray { | ||
// fn area(&self) -> Result<PrimitiveArray<f64>> { | ||
// Ok(zeroes(self.len(), self.validity())) | ||
// } | ||
// } | ||
|
||
// /// Implementation where the result is zero. | ||
// macro_rules! zero_impl { | ||
// ($type:ty) => { | ||
// impl<O: Offset> Area for $type { | ||
// fn area(&self) -> Result<PrimitiveArray<f64>> { | ||
// Ok(zeroes(self.len(), self.validity())) | ||
// } | ||
// } | ||
// }; | ||
// } | ||
|
||
// zero_impl!(LineStringArray<O>); | ||
// zero_impl!(MultiPointArray<O>); | ||
// zero_impl!(MultiLineStringArray<O>); | ||
|
||
// macro_rules! iter_geos_impl { | ||
// ($type:ty) => { | ||
// impl<O: Offset> Area for $type { | ||
// fn area(&self) -> Result<PrimitiveArray<f64>> { | ||
// } | ||
// } | ||
// }; | ||
// } | ||
|
||
// iter_geos_impl!(PolygonArray<O>); | ||
// iter_geos_impl!(MultiPolygonArray<O>); | ||
// iter_geos_impl!(WKBArray<O>); | ||
|
||
// impl<O: Offset> Area for GeometryArray<O> { | ||
// crate::geometry_array_delegate_impl! { | ||
// fn area(&self) -> Result<PrimitiveArray<f64>>; | ||
// } | ||
// } | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use crate::test::point::point_array; | ||
|
||
#[test] | ||
fn point_buffer() { | ||
let arr = point_array(); | ||
let buffered = arr.buffer(1., 8).unwrap(); | ||
dbg!(buffered); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod area; | ||
pub mod buffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ pub use mutable::MutableLineStringArray; | |
|
||
mod array; | ||
pub mod iterator; | ||
mod mutable; | ||
pub(crate) mod mutable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,4 @@ pub use mutable::MutablePointArray; | |
|
||
mod array; | ||
pub mod iterator; | ||
mod mutable; | ||
pub(crate) mod mutable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.