Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API | distance between h3s challenging to work around #840

Closed
fhk opened this issue May 14, 2024 · 5 comments
Closed

API | distance between h3s challenging to work around #840

fhk opened this issue May 14, 2024 · 5 comments

Comments

@fhk
Copy link

fhk commented May 14, 2024

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?

    edges = {}
    for h in data_center_locations['h3_3']:
        for d in demand_locations['h3_3']:
            edges[i_j_hex[d], i_j_hex[h]] = h3.great_circle_distance(d, h)
@ajfriend
Copy link
Contributor

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?

@nrabinowitz
Copy link
Collaborator

There's also gridDistance, which gives you the distance in grid steps between two cells. This might be appropriate for some modeling tasks.

@fhk
Copy link
Author

fhk commented May 14, 2024

ah @ajfriend apologies I couldn't locate this in the new docs!

@fhk fhk closed this as completed May 14, 2024
@fhk
Copy link
Author

fhk commented May 14, 2024

https://h3geo.org/docs/library/migration-3.x/functions/ any idea what it is in 4.x?

@dfellis
Copy link
Collaborator

dfellis commented May 14, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants