I would like to split complex geometries into n smallest geometries of the same area in Python. While I can divide simple geometry in the following way:
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
I am not able to find a way to do the same for complex geometries.
Is there any similar plugin or function in Python like Splitting polygon into equal area polygons in QGIS 3?
A geometry could be the following one that can be dowloaded here
