H3¶
Utility H3 related functions.
Functions¶
¶
Buffer a Shapely geometry with H3 cells, and return the bounding geometry.
If a GeoDataFrame is passed, the geometry column will be used and the return will be a GeoSeries
PARAMETER | DESCRIPTION |
---|---|
geometry |
The geometry to buffer.
TYPE:
|
h3_resolution |
The H3 resolution to use.
TYPE:
|
distance |
The k-ring buffer distance in H3 cells.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[gpd.GeoSeries, BaseGeometry]
|
Union[gpd.GeoSeries, BaseGeometry]: The buffered geometry. |
Source code in srai/h3.py
¶
Calculate the local H3 ij index based on provided origin index.
Wraps H3's cell_to_local_ij function and centers returned coordinates around provided origin cell.
PARAMETER | DESCRIPTION |
---|---|
origin_index |
H3 index of the origin region.
TYPE:
|
h3_index |
H3 index of the second region or list of regions.
TYPE:
|
return_as_numpy |
Flag whether to return calculated indexes as a Numpy array or a list of tuples.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[tuple[int, int], list[tuple[int, int]], npt.NDArray[np.int8]]
|
Union[Tuple[int, int], List[Tuple[int, int]], npt.NDArray[np.int8]]: The local ij index of the second region (or regions) with respect to the first one. |
Source code in srai/h3.py
¶
Buffer H3 indexes by a given number of k-rings.
List of provided H3 indexes will be buffered by a given distance.
PARAMETER | DESCRIPTION |
---|---|
h3_indexes |
List of H3 indexes to be buffered.
TYPE:
|
distance |
The k-ring buffer distance in H3 cells.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
List[str]: Buffered list of H3 cells containing both original and new cells. |
Source code in srai/h3.py
¶
Convert H3 index to Shapely polygon.
PARAMETER | DESCRIPTION |
---|---|
h3_index |
H3 index (or list of indexes) to be converted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Union[Polygon, list[Polygon]]
|
Union[Polygon, List[Polygon]]: Converted polygon (or list of polygons). |
Source code in srai/h3.py
¶
Convert Shapely geometry to H3 indexes.
PARAMETER | DESCRIPTION |
---|---|
geometry |
Shapely geometry to be converted.
TYPE:
|
h3_resolution |
H3 resolution of the cells. See [1] for a full comparison.
TYPE:
|
buffer |
Whether to fully cover the geometries with H3 Cells (visible on the borders). Defaults to True.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
List[str]: List of H3 indexes that cover a given geometry. |
RAISES | DESCRIPTION |
---|---|
ValueError
|
If resolution is not between 0 and 15. |
Source code in srai/h3.py
¶
Convert H3 index to GeoPandas GeoSeries.
PARAMETER | DESCRIPTION |
---|---|
h3_index |
H3 index (or list of indexes) to be converted.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
GeoSeries
|
Geometries as GeoSeries with default CRS applied.
TYPE:
|
Source code in srai/h3.py
¶
Buffer H3 indexes by a given number of k-rings.
List of provided H3 indexes will be buffered by a given distance.
PARAMETER | DESCRIPTION |
---|---|
regions_gdf |
GeoDataFrame with H3 regions from H3Regionalizer.
TYPE:
|
distance |
The k-ring buffer distance in H3 cells.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
gpd.GeoDataFrame
|
gpd.GeoDataFrame: Buffered regions_gdf with new H3 cells added. |