Skip to content

Add algorithm for intersection of geometries with a rectangular grid #967

Open
@dbaston

Description

@dbaston

I am working on a project to expose the exactextract library to Python in a way similar to the R package exactextractr.

Instead of creating separate Python bindings for this library, I am considering attempting to move much of the code of this library into GDAL where it would become accessible through GDAL's Python bindings. Related but not necessarily dependent on this, I am thinking about whether some of the code could move into GEOS -- specifically, an optimized intersection calculation between rectangular grids and polygonal/linear geometries.

The result of the overlay is most commonly expressed as the fraction of each grid cell that is covered by a polygon, although it is also possible to get the total length of linear geometries within each grid cell or (more experimentally) a Geometry representation of each polygon/grid cell intersection, e.g.

image

This code has a strong test suite and has had pretty good public adoption since the R package was published in 2019, so I think it can be considered reasonably mature.

I don't have a detailed proposal yet, but I imagine that a minimal-footprint addition to GEOS would add something along these lines:

// define a grid
GEOSGrid* GEOSGrid_create(double xmin, double ymin, double xmax, double ymax, double dx, double dy);

// calculate a Grid coincident with `grid` but covering only `geom`
GEOSGrid* GEOSGrid_clip(const GEOSGrid* grid, const GEOSGeometry* geom);

// partition a polygonal geometry by a grid
GEOSGeometry* GEOSGrid_intersection(const GEOSGrid* grid, const GEOSGeometry* geom);

// calculate a raster with the fraction of each grid cell that is covered
// to avoid introducing a matrix type (and having slow access through non-inlined function calls)
// just return a float* and access values with x[i*cols + j] or something
float* GEOSGrid_intersectionAreas(const GEOSGrid*, const GEOSGeometry* geom);

Just thought I'd create an issue for this in case anyone has thoughts. I'm going to aim to have a better formed proposal before the Vienna code sprint.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions