diff options
Diffstat (limited to 'lib/utils/clamp_path.py')
| -rw-r--r-- | lib/utils/clamp_path.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/utils/clamp_path.py b/lib/utils/clamp_path.py index f1fc7765..f9b8991a 100644 --- a/lib/utils/clamp_path.py +++ b/lib/utils/clamp_path.py @@ -66,6 +66,8 @@ def find_border(polygon, point): def clamp_path_to_polygon(path, polygon): """Constrain a path to a Polygon. + The path is expected to have at least some part inside the Polygon. + Description: https://gis.stackexchange.com/questions/428848/clamp-linestring-to-polygon """ @@ -76,6 +78,10 @@ def clamp_path_to_polygon(path, polygon): # border and returns the pieces in the same order as the original path. split_path = ensure_geometry_collection(LineString(path).difference(polygon.boundary)) + if len(split_path.geoms) == 1: + # The path never intersects with the polygon, so it's entirely inside. + return path + # Add the start and end points to avoid losing part of the path if the # start or end coincides with the polygon boundary split_path = [ShapelyPoint(start), *split_path.geoms, ShapelyPoint(end)] |
