H3¶
Utility H3 related functions.
Functions¶
srai.h3.ring_buffer_geometry ¶
ring_buffer_geometry(
geometry: Union[
BaseGeometry, Iterable[BaseGeometry], gpd.GeoSeries, gpd.GeoDataFrame
],
h3_resolution: int,
distance: int,
) -> Union[gpd.GeoSeries, BaseGeometry]
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[GeoSeries, BaseGeometry]
|
Union[gpd.GeoSeries, BaseGeometry]: The buffered geometry. |
Source code in srai/h3.py
srai.h3.h3_to_geoseries ¶
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
srai.h3.get_local_ij_index ¶
get_local_ij_index(
origin_index: str,
h3_index: Union[str, list[str]],
return_as_numpy: bool = False,
) -> Union[tuple[int, int], list[tuple[int, int]], npt.NDArray[np.int8]]
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]], NDArray[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
srai.h3.h3_to_shapely_geometry ¶
h3_to_shapely_geometry(
h3_index: Union[int, str, Iterable[Union[int, str]]],
) -> Union[Polygon, list[Polygon]]
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
srai.h3.ring_buffer_h3_regions_gdf ¶
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 |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: Buffered regions_gdf with new H3 cells added. |
Source code in srai/h3.py
srai.h3.ring_buffer_h3_indexes ¶
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
srai.h3.shapely_geometry_to_h3 ¶
shapely_geometry_to_h3(
geometry: Union[
BaseGeometry, Iterable[BaseGeometry], gpd.GeoSeries, gpd.GeoDataFrame
],
h3_resolution: int,
buffer: bool = True,
) -> list[str]
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. |