I would like to divide a complex geometry into n
subgeometries of the same area.
For instance if I have a rectangle I can do something like this
from shapely.geometry import LineString, MultiPolygon, Polygon
from shapely.ops import split
def splitPolygon(polygon, nx, ny):
minx, miny, maxx, maxy = polygon.bounds
dx = (maxx - minx) / nx
dy = (maxy - miny) / ny
minx, miny, maxx, maxy = polygon.bounds
dx = (maxx - minx) / nx # width of a small part
dy = (maxy - miny) / ny # height of a small part
horizontal_splitters = [LineString([(minx, miny + i*dy), (maxx, miny + i*dy)]) for i in range(ny)]
vertical_splitters = [LineString([(minx + i*dx, miny), (minx + i*dx, maxy)]) for i in range(nx)]
splitters = horizontal_splitters + vertical_splitters
result = polygon
for splitter in splitters:
result = MultiPolygon(split(result, splitter))
return result
myPolygons = splitPolygon(polygon, 5, 5)
import geopandas as gpd
gdfR = gpd.GeoDataFrame(columns=['geometry'], data=myPolygons.geoms)
f,ax=plt.subplots()
gdfR.boundary.plot(ax=ax, color='red')
polygon.boundary.plot(ax=ax)
I would like to split a complex geometry like following one into n
smallest geometries of the same area. Is possible to download the geometry as shapefile here.