Search code examples
pythonh3

Is the geoToH3 function as pseudo-code available?


Is there a (python) or pseudocode example of geoToH3 available? I just need this function and would like to avoid installing the library on my target environment (AWS GLUE, PySpark)

I tried to follow the javascript implementation but even that used C magic internally.


Solution

  • There isn't a pseudocode implementation that I'm aware of, but there's a fairly thorough explanation in the documentation. Roughly:

    • Select the icosahedron face (0-20) the point lies on (using point square distance in 3d space)
    • Project the point into face-oriented IJK coordinates
    • Convert the IJK coords to an H3 index by calculating the index digits at each resolution and setting the appropriate bits

    The core logic can be found here and here. It's not trivial to implement - unless there's a strong reason to avoid installing, that would be the far easier and more reliable option.