Deltares / xugrid

Xarray and unstructured grids
https://deltares.github.io/xugrid/
MIT License
53 stars 8 forks source link

Investigate faster polygon operations #218

Open Huite opened 4 months ago

Huite commented 4 months ago

The current burn_vector_geometry relies on calling earcut to break a polygon down into a triangular mesh, which is then checked for overlap. I don't necessarily see a better way for all_touched=True since it relies on computing overlaps. But in case of all_touched=False, it's just searching for centroids.

In this case, it's just a point in polygon check. The ad hoc benchmarking seemed to show that is was beating geopandas points-in-polygon, but not massively so (something like one order of magnitude).

I came across these two:

https://github.com/dengwirda/inpoly https://github.com/KlausC/PolygonInbounds.jl

They do some prior work so it should be more efficient to search collections of points. It would be worthwhile to investigate, although it should maybe end up in numba-celltree instead.