uber / h3-js

h3-js provides a JavaScript version of H3, a hexagon-based geospatial indexing system.
https://uber.github.io/h3
Apache License 2.0
875 stars 79 forks source link

how can i detect a coordinate (point) inside hexagon #132

Closed abilican closed 2 years ago

abilican commented 2 years ago

Hi, I know there are many different ways to find that a coordinate is inside a hexagon or not but. I searched in h3js but couldn't find. Do you suggest any way that you used before with h3js? If I find exactly work a solution, i'll write here.

dfellis commented 2 years ago

Inside an H3-defined hexagon or any arbitrary hexagon on the planet?

H3 is a grid system, so arbitrary hexagons not aligned with its grid won't work, and you should use a "point-in-poly" library to do this along with the hexagon in question.

If it is an H3 hexagon, you can just run geoToH3 at the same resolution as your current H3 hexagon and just check if the IDs are identical or not.

abilican commented 2 years ago

Yes, it's h3 hexegon, as you said, just compering h3Indexes enought for know coordinate is in hexagon. it's my fault, I approached to problem from a geometric perspective. Thanks so much @dfellis.