georust / geozero

Zero-Copy reading and writing of geospatial data.
Apache License 2.0
321 stars 30 forks source link

`BufferedGeozeroDatasource` for spatial filtering on reading #197

Open kylebarron opened 4 months ago

kylebarron commented 4 months ago

It's often desired to prevent materialization of data features outside of some spatial region, usually a bounding box. Some formats, like FlatGeobuf, GeoPackage, and Shapefile, have a native implementation of spatial filtering, but others, like CSV, GeoJSON, GeoJSON Lines, don't have any built-in method to the format.

A simple way to handle this spatial filtering in general would be to implement a BufferedGeozeroDatasource. It would wrap a general GeozeroDatasource and its constructor would include a bbox parameter. It would buffer up to one feature, determine whether the geometry intersects the input bbox, and if so, propagate that feature on to the consumer.

I'm interested in implementing this kind of thing for the geoarrow crate but it might be general enough to live in the geozero crate. Thoughts?