I'm working on splitting a polygon given a set of linestrings using the shapely python library. The problem I'm facing is that a polygon cannot be split by a MultiLineString usingshapely.ops.split(geom, splitter)
.
The desired result in the image above is to split polygon (blue) with the linestrings (yellow, brown, red) and recieve 4 seperate polygons (1,2,3,4). The geometries in the image are provided below. It is preferred to do this within shapely.
polygon = shapely.geometry.polygon.Polygon(
[(172288.6111791851, 442085.8603492165),
(172300.89001713035, 442131.53561756504),
(171916.83106749243, 442140.9016841368),
(171910.779533863, 442014.47234046715),
(172165.44614826166, 442016.17982713436),
(172188.0201264064, 442022.13092037174),
(172189.32585150487, 442047.592559792),
(172159.87170649506, 442049.9277989104),
(172169.13733267464, 442085.8603492165),
(172288.6111791851, 442085.8603492165)])
coords = [((172159.87170649506, 442016.14245166205),
(172159.87170649506, 442049.9277989104)),((172159.87170649506, 442049.9277989104),
(172159.87170649506, 442134.97463880514)),((172169.13733267464, 442085.8603492165),
(172169.13733267464, 442134.74867747363))]
lines = shapely.geometry.MultiLineString(coords)
Best Answer
adopted the answer from this post: Splitting Polygon by Linestring in GeoDjango?.
The lines for splitting are slightly extended in both directions (0.01) in order to ensure that they cross the input polygon border, therefore making the unary_union work.