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
872 stars 79 forks source link

2D Projection? #102

Closed notflip closed 3 years ago

notflip commented 4 years ago

This lib is working fine but there's a (to be expected) distortion, is there a simple way to represent the hexagons in a flat 2D way?

nrabinowitz commented 3 years ago

That's an interesting question, and it depends on your use case. The underlying representation of the grid does not have distortion, but this grid is projected (via inverse gnomonic projection, see some explanation here) to get the lat/long coords for each cell. This creates the distortion you describe. However, you can reverse the transformation when rendering with a gnomonic projection, as demonstrated here: https://observablehq.com/@nrabinowitz/flat-h3-grid-via-gnomonic-projection

This only works if you have control over the projection of your map, of course, and only when all the cells you want to render are on the same icosahedron face.