Python bindings for H3, a hierarchical hexagonal geospatial indexing system
84
Create a small utility that summarizes where an input H3 cell sits in the hierarchy, including its parent at a coarser resolution, every child at a finer resolution, the center child, and the child's positional index within its parent.
8928308280fffff, a parent resolution of 7, and a child resolution of 9, return the parent index at resolution 7 and the full list of resolution 9 children for that parent. The children list must contain 49 entries and include the original cell. @test@generates
from typing import TypedDict
class HierarchySummary(TypedDict):
parent: str
parent_resolution: int
children: list[str]
child_resolution: int
center_child: str
center_is_input: bool
child_position: int
reconstructed_child: str
def summarize_hierarchy(cell: str, parent_resolution: int, child_resolution: int) -> HierarchySummary:
"""
Build a hierarchy summary for a given cell.
Args:
cell: H3 cell index string at resolution >= parent_resolution
parent_resolution: target coarser resolution for parent lookup
child_resolution: target finer resolution for enumerating children
Returns:
Summary describing the parent index, children at the child resolution,
whether the input is the center child, and a roundtrip reconstruction
of the original cell from its positional index within the parent.
"""Provides hierarchical traversal between parent and child cells plus position mapping.
Install with Tessl CLI
npx tessl i tessl/pypi-h3docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10