Split a Polygon with a LineString.
(poly, splitter)
| 344 | class SplitOp: |
| 345 | @staticmethod |
| 346 | def _split_polygon_with_line(poly, splitter): |
| 347 | """Split a Polygon with a LineString.""" |
| 348 | if not isinstance(poly, Polygon): |
| 349 | raise GeometryTypeError("First argument must be a Polygon") |
| 350 | if not isinstance(splitter, (LineString, MultiLineString)): |
| 351 | raise GeometryTypeError("Second argument must be a (Multi)LineString") |
| 352 | |
| 353 | union = poly.boundary.union(splitter) |
| 354 | |
| 355 | # greatly improves split performance for big geometries with many |
| 356 | # holes (the following contains checks) with minimal overhead |
| 357 | # for common cases |
| 358 | poly = prep(poly) |
| 359 | |
| 360 | # some polygonized geometries may be holes, we do not want them |
| 361 | # that's why we test if the original polygon (poly) contains |
| 362 | # an inner point of polygonized geometry (pg) |
| 363 | return [ |
| 364 | pg for pg in polygonize(union) if poly.contains(pg.representative_point()) |
| 365 | ] |
| 366 | |
| 367 | @staticmethod |
| 368 | def _split_line_with_line(line, splitter): |
nothing calls this directly
no test coverage detected