H3 Regionalizer Example¶
In [1]:
Copied!
import geopandas as gpd
from shapely import geometry
from srai.regionalizers import H3Regionalizer
from srai.plotting.folium_wrapper import plot_regions
from srai.constants import WGS84_CRS
import geopandas as gpd
from shapely import geometry
from srai.regionalizers import H3Regionalizer
from srai.plotting.folium_wrapper import plot_regions
from srai.constants import WGS84_CRS
Define starting polygons¶
In [2]:
Copied!
gdf = gpd.GeoDataFrame(
geometry=[
geometry.Polygon(
shell=[
(-1, 0),
(0, 0.5),
(1, 0),
(1, 1),
(0, 1),
],
holes=[
[
(0.8, 0.9),
(0.9, 0.55),
(0.8, 0.3),
(0.5, 0.4),
]
],
),
geometry.Polygon(shell=[(-0.25, 0), (0.25, 0), (0, 0.2)]),
],
crs=WGS84_CRS,
)
gdf.explore()
gdf = gpd.GeoDataFrame(
geometry=[
geometry.Polygon(
shell=[
(-1, 0),
(0, 0.5),
(1, 0),
(1, 1),
(0, 1),
],
holes=[
[
(0.8, 0.9),
(0.9, 0.55),
(0.8, 0.3),
(0.5, 0.4),
]
],
),
geometry.Polygon(shell=[(-0.25, 0), (0.25, 0), (0, 0.2)]),
],
crs=WGS84_CRS,
)
gdf.explore()
Out[2]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Define H3 resolution¶
In [3]:
Copied!
resolution = 5
resolution = 5
Regionalize using H3 without buffering¶
Polygons are not fully covered in H3 cells
In [4]:
Copied!
regionalizer = H3Regionalizer(resolution, buffer=False)
gdf_h3 = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_h3, colormap=["red"], map=folium_map)
regionalizer = H3Regionalizer(resolution, buffer=False)
gdf_h3 = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_h3, colormap=["red"], map=folium_map)
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Regionalize using H3 with buffering (default)¶
Polygons are now properly covered in H3 cells
In [5]:
Copied!
regionalizer_buffered = H3Regionalizer(resolution)
gdf_h3_buffered = regionalizer_buffered.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_h3_buffered, colormap=["red"], map=folium_map)
regionalizer_buffered = H3Regionalizer(resolution)
gdf_h3_buffered = regionalizer_buffered.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_h3_buffered, colormap=["red"], map=folium_map)
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook