Closed fhk closed 3 months ago
h3.cell_to_latlng
gives the centroid of an H3 cell.
If you have H3 cell ids h
and d
, you can compute the Haversine distance between their centroids with:
h1 = h3.cell_to_latlng(h)
d1 = h3.cell_to_latlng(d)
distance = h3.great_circle_distance(d1, h1)
Does that cover your use case?
There's also gridDistance
, which gives you the distance in grid steps between two cells. This might be appropriate for some modeling tasks.
ah @ajfriend apologies I couldn't locate this in the new docs!
https://h3geo.org/docs/library/migration-3.x/functions/ any idea what it is in 4.x?
@fhk I think part of the confusion on your end is that you're using the documentation for the core C library but comparing it to the Python bindings. The Java and Javascript bindings stick really close to the core C library's naming system (with all three being camelCase
), but the Python library deviates from that.
There's some effort to include Python in most of the pages, but that particular page does not include it. Because of this and some other ways the Python library deviates or adds extra features (such as the H3Shape
type), there's a second set of documentation just for it that may be useful to you.
It should be easy given two h3 indexes to calculate their distance from one another, either from centroid or perhaps nearest vertices.
When making models you often want to encode start and end edges and the distance.
This is now hard as there is no centroid method on the h3?
You have to go through the whole __geo_interface__ or hope that the outer ordering is consistent?