diff options
| author | Lex Neva <github.com@lexneva.name> | 2023-05-29 21:55:17 -0400 |
|---|---|---|
| committer | Kaalleen <reni@allenka.de> | 2023-07-01 08:23:46 +0200 |
| commit | f9438ac9ff5886f25e4ad18271769ef77de806d0 (patch) | |
| tree | f77709caf7b6232421e0788f6cbf6fbb93771291 | |
| parent | ec68c17a05aa4a3d75fcab069a3b065f473574af (diff) | |
return early for paths already inside
| -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)] |
