Indexing

  • Cells are uniquely identified by a UInt64 index. The only global indexing system is through these values.
    • You can create cells from its index or from coordinates that are contained in the cell: Cell(index) or Cell((lon, lat), res=10).
  • However, H3 supports several other indexing systems that are valid within a single face of the icosahedron.
  • HexEarth uses several different getindex methods to expose these indexing systems.
Index Ordering

Index ordering is not consistent. I.e. there are no directional guarantees as to where cell[1] is relative to cell.

julia> using HexEarth
julia> new_york = (-74, 40.7)(-74, 40.7)
julia> cell = Cell(new_york) Cell 10 (-74.00025337207035, 40.699690184228594)
julia> cell[1] # spiral indexing (1-6) for immediate neighbors Cell 10 (-74.00179375894132, 40.70002575242847)
julia> cell[0, 1] # https://h3geo.org/docs/core-library/coordsystems#local-ij-coordinates Cell 10 (-74.00179375894132, 40.70002575242847)
julia> cell[0, 1, 0] # https://h3geo.org/docs/core-library/coordsystems#ijk-coordinates Cell 10 (-74.00179375894132, 40.70002575242847)

Spiral Indexing

import GeoInterface as GI
using CairoMakie

fig = Figure()
ax = Axis(fig[1,1])
poly!(ax, cell)
for i in 1:6
    lines!(ax, cell[i])
    text!(ax, GI.centroid(cell[i]), text=string(i))
end
fig
Example block output

IJ Indexing

Note

For IJ/IJK indexing, HexEarth uses the conventions that (0,0) and (0,0,0) refer to the origin cell. For whatever reason, this is not the case in the original h3 library.

fig = Figure()
ax = Axis(fig[1,1])
poly!(ax, cell)
for i in [(0,1), (0,-1), (-1,-1), (1,1), (1,0), (-1,0)]
    lines!(ax, cell[i...])
    text!(ax, GI.centroid(cell[i...]), text=string(i))
end
fig
Example block output

IJK Indexing

fig = Figure()
ax = Axis(fig[1,1])
poly!(ax, cell)
for i in HexEarth.neighbor_indices
    @info i
    lines!(ax, cell[i...])
    text!(ax, GI.centroid(cell[i...]), text=string(i))
end
fig
Example block output