S2 Regionalizer Example¶
In [1]:
Copied!
import geopandas as gpd
from shapely import geometry
from srai.regionalizers import S2Regionalizer
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 S2Regionalizer
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 S2 resolution¶
In [3]:
Copied!
resolution = 10
resolution = 10
Regionalize using S2 wihtout buffer¶
All cells are fully contained in the original polygon.
In [4]:
Copied!
regionalizer = S2Regionalizer(resolution, buffer=False)
gdf_s2 = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_s2, colormap=["red"], map=folium_map)
regionalizer = S2Regionalizer(resolution, buffer=False)
gdf_s2 = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_s2, colormap=["red"], map=folium_map)
Out[4]:
Make this Notebook Trusted to load map: File -> Trust Notebook
Regionalize using S2 with buffer (default)¶
Whole polygon is covered by cells. Some are not fully contained in the original polygon.
In [5]:
Copied!
regionalizer = S2Regionalizer(resolution, buffer=True)
gdf_s2_buffered = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_s2_buffered, colormap=["red"], map=folium_map)
regionalizer = S2Regionalizer(resolution, buffer=True)
gdf_s2_buffered = regionalizer.transform(gdf)
folium_map = gdf.explore()
plot_regions(gdf_s2_buffered, colormap=["red"], map=folium_map)
Out[5]:
Make this Notebook Trusted to load map: File -> Trust Notebook