gedih3.h3utils#
Functions#
|
Get all H3 hexagons at a given resolution level |
|
Memory-efficient iterator for all H3 hexagons at resolution |
|
Using the antimeridian package for robust handling. |
|
Expand a set of H3 cells by their |
|
Return H3 cells whose data footprint may intersect |
|
|
|
Convert H3 partition IDs to a GeoDataFrame with polygon geometries. |
Module Contents#
- gedih3.h3utils.get_all_h3_hexagons(resolution: int)[source]#
Get all H3 hexagons at a given resolution level
- gedih3.h3utils.iter_all_h3_hexagons(resolution: int)[source]#
Memory-efficient iterator for all H3 hexagons at resolution
- gedih3.h3utils.fix_h3_geometry(hex: str)[source]#
Using the antimeridian package for robust handling.
- gedih3.h3utils.h3_expand_ring(cells, ring=1, valid=None)[source]#
Expand a set of H3 cells by their
grid_diskneighbors.The shared overhang-safety primitive: shots are stored under their hierarchy partition, which can overhang the partition’s polygon by ~0.18 x edge length (see
_H3_OVERHANG_FRACTIONin utils.py) — far less than one cell width, so any cell set selected by exact polygon intersection only needs its ring-1 neighbors to cover all storage partitions. Used byintersect_h3_geometries,egi_h3_intersectionandgeoseries_to_filter.- Parameters:
- cellsiterable of str
H3 cell IDs (all at the same resolution).
- ringint, default 1
grid_diskradius.- validset, optional
When given, only neighbors in this set are added (e.g. the partitions that actually exist in a database).
- Returns:
- list[str]
Sorted union of
cellsand their (filtered) neighbors.
- gedih3.h3utils.intersect_h3_geometries(spatial, res=3, h3_ids=None, expand_ring=1)[source]#
Return H3 cells whose data footprint may intersect
spatial.H3 children are not geometrically contained in their parents: a shot stored under partition
cell_to_parent(latlng_to_cell(lon, lat, index_res), part_res)can sit up to ~0.14-0.16 x the parent’s edge length outside the parent’s own polygon (~8-10 km at partition level 3; see_H3_OVERHANG_FRACTIONin utils.py). A ROI touching that overhang band intersects the polygon the shots physically fall in, not the partition they are stored in — so an exact polygon intersection silently misses boundary shots (observed in production on the EGI path: ~5% of one L3 partition’s shots; seeegi_h3_intersection).expand_ring=1(default) closes this by adding the grid_disk ring-1 neighbors of every polygon-intersecting cell, restricted to the candidate set (h3_idswhen given). This is guaranteed sufficient: the overhang (~0.18 x edge) is far smaller than one cell width, so the true storage partition of any shot inside a polygon is always that polygon’s cell or an immediate neighbor. Callers that need the exact polygon intersection can passexpand_ring=0.- Parameters:
- spatialstr | list | GeoSeries | GeoDataFrame | shapely geometry
ROI as a vector-file path / “W,S,E,N” string, [W,S,E,N] bbox list, geopandas object, or shapely geometry (EPSG:4326).
- resint
H3 resolution of the candidate cells (ignored when
h3_idsgiven).- h3_idslist, optional
Candidate cell set (e.g. a database’s partition ids). When given, both the intersection and the ring expansion are restricted to it.
- expand_ringint, default 1
grid_diskradius for the overhang-safety expansion; 0 disables.