Grid traversal¶
Find nearby cells, grid distances, and paths.
grid_disk¶
Return the origin and all cells no more than k grid steps away.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"cell": ["85283473fffffff"]})
df.select(cells=plh3.grid_disk("cell", k=1))
shape: (1, 1)
┌───────────────────────────┐
│ cells │
│ --- │
│ list[str] │
╞═══════════════════════════╡
│ ["85283473fffffff", "852… │
└───────────────────────────┘
grid_ring¶
Return cells exactly k grid steps from the origin.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame({"cell": ["85283473fffffff"]})
df.select(cells=plh3.grid_ring("cell", k=1))
shape: (1, 1)
┌───────────────────────────┐
│ cells │
│ --- │
│ list[str] │
╞═══════════════════════════╡
│ ["8528340bfffffff", "852… │
└───────────────────────────┘
grid_distance¶
Return the minimum number of grid steps between two cells.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame(
{
"origin": ["85283473fffffff"],
"destination": ["85283447fffffff"],
}
)
df.select(distance=plh3.grid_distance("origin", "destination"))
grid_path_cells¶
Return a minimal contiguous path including both endpoints.
import polars as pl
import polars_h3 as plh3
df = pl.DataFrame(
{
"origin": ["85283473fffffff"],
"destination": ["8528341bfffffff"],
}
)
df.select(path=plh3.grid_path_cells("origin", "destination"))
shape: (1, 1)
┌───────────────────────────┐
│ path │
│ --- │
│ list[str] │
╞═══════════════════════════╡
│ ["85283473fffffff", "852… │
└───────────────────────────┘
Traversal failures
Origins and destinations must have compatible resolutions. Pentagon distortion can make some paths unavailable.