xarray-contrib / xdggs

Xarray extension for DGGS
https://xdggs.readthedocs.io
Apache License 2.0
79 stars 14 forks source link

Spatial indexing #16

Open benbovy opened 1 year ago

benbovy commented 1 year ago

Currently a DGGSIndex only wraps a PandasIndex, which is limited for spatial indexing:

A general solution for spatial indexing might be to follow the approach used in h3ron-polars, which provides a few spatial indexes (kd-tree, r-tree, packed-hilbert-rtree) that work with either the cell centroids or their envelope (rectangle). We could probably do the same here. We might be able to eventually reuse the indexes implemented in xoak once it is refactored to leverage Xarray custom indexes.

Alternatively, we could extract the cell geometries (#10) and then just rely on (or redirect users to) xvec for spatial queries. Xvec's GeometryIndex internally reuses GEOS' STRTree via shapely 2.0.

danlooo commented 6 months ago

I tried spatial indicies e.g. a k-d tree for the DGGRID DGGS in https://github.com/danlooo/DGGS.jl/issues/34 Searching for the nearest neighbor i.e. cell center lat/lon coordinate failed in reassembling the cell polygon geometry leading into many points that are assigned to a wrong cell. This is because the cell polygons are not regular anymore after the Snyder Equal Area Projection.