uber / h3

Hexagonal hierarchical geospatial indexing system
https://h3geo.org
Apache License 2.0
4.83k stars 459 forks source link

Child cell lat/lng outside of parent lat/lng ? #750

Closed jogoussard closed 1 year ago

jogoussard commented 1 year ago

Hi I'm looking at a resolution 6 H3 cell 86139ec57ffffff and at one of it resolution 9 child 89139ec5493ffff. The library correctly states via cellToChildren or cellToParent that both are related, but when using cellToBoundary I get lat/lng for the child cell outside of the boundaries of the parent cell. The resulting two geometries are GEOMETRYCOLLECTION(POLYGON((-134.7726597 58.428654900000026,-134.7926704 58.40057869999998,-134.7571973 58.374116000000015,-134.7017216 58.37569730000001,-134.6816275 58.403761799999955,-134.7170924 58.43025670000003,-134.7726597 58.428654900000026)),POLYGON((-134.7619536 58.431210300000004,-134.7593701 58.43016260000002,-134.7566931 58.430801299999985,-134.7565995 58.43248779999996,-134.7591832 58.433535500000005,-134.7618603 58.432896700000015,-134.7619536 58.431210300000004))) and you can see (for ex on https://clydedacruz.github.io/openstreetmap-wkt-playground/) that the child is well outside of the parent. I was expecting every child to at least intersect with the parent geometry. Is this expected due to distortion at these latitudes?

isaacbrodsky commented 1 year ago

Yes, this is expected from H3. There are some more details of this on https://h3geo.org/docs/highlights/indexing. These child cells are logically but not necessarily geographically contained.

This is not an effect of latitude but rather a property of the hierarchical hexagonal grid. Hexagons do not cleanly subdivide into 7 children, so there is a fractal pattern around the edges as you subdivide.

jogoussard commented 1 year ago

Okay, thanks a lot for clarifying - I guess if I had computed the chain of children from resolution 6 to 9 I would have seen this. I guess my thinking was mislead by the usual example of the doc where only the direct children are shown.