xarray-contrib / xdggs

Xarray extension for DGGS
Apache License 2.0
54 stars 9 forks source link

compute cell boundaries from cell ids #30

Open keewis opened 9 months ago

keewis commented 9 months ago

This works pretty well for healpix, but not really for h3 (using h3ronpy): h3ronpy.arrow.vector.cells_to_wkb_polygons unnecessarily converts to WKB, and h3ronpy.pandas.vector.cells_to_polygons depends on geopandas (which for now I guess is fine, but we might want to figure out how to get rid of the dependency).

The API currently is based on properties, but we can just as well convert to methods.

benbovy commented 9 months ago

h3ronpy.arrow.vector.cells_to_wkb_polygons unnecessarily converts to WKB, and h3ronpy.pandas.vector.cells_to_polygons depends on geopandas (which for now I guess is fine, but we might want to figure out how to get rid of the dependency).

Looking at the h3ronpy source, it looks like the latter wraps the former to create a geopandas GeoSeries from the WKB conversion, so it won't be very useful here.

I think it is fine (although not ideal) to convert to WKB, assuming that h3ronpy does that in a vectorized way. Given that shapely 2 can create polygon objects from WKB also in a vectorized way, both will already provide a reasonable level of performance I think (better than the current existing alternatives).

benbovy commented 9 months ago

The API currently is based on properties, but we can just as well convert to methods.

I think I'd vote for methods, since this might involve quite a bit of computation (not just returning some internal attribute or cached value).

keewis commented 7 months ago

I'm not sure how to best test this... @benbovy, do you have any ideas? Otherwise this should be ready for use.

keewis commented 2 months ago

looks like to be useful in all cases, we need to think about how poles and date line / prime meridian can be worked around with shapely: at the moment, if I ask xvec to select a bounding box based on the polygons for healpix cells, it may include cells that cross the date prime meridian (since healpix uses the 0-360 convention), even if the search area is on the other side of the globe. Not sure if H3 would have the same issue.

I guess to truly resolve this we need spherely, but I'm wondering if we can somehow work around this with shapely. I've tried manually applying the wrapping if:

but this does not appear to work as well as I would like it to. Maybe we can instead map the longitudes so the vertices are in roughly the same distance from the cell centers.

Does anyone have any other ideas?