summaryrefslogtreecommitdiff
path: root/lib/utils/geometry.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/utils/geometry.py')
-rw-r--r--lib/utils/geometry.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py
index 541d9cbc..e5296ef0 100644
--- a/lib/utils/geometry.py
+++ b/lib/utils/geometry.py
@@ -179,6 +179,18 @@ def ensure_multi_point(thing):
return multi_point
+def ensure_polygon(thing):
+ """Given a Polygon or a MultiPolygon
+
+ Returns the Polygon or the biggest Polygon of the MultiPolygon"""
+
+ if thing.geom_type == "MultiPolygon":
+ thing = list(thing.geoms)
+ thing.sort(key=lambda thing: thing.area, reverse=True)
+ return thing[0]
+ return thing
+
+
def cut_path(points, length):
"""Return a subsection of at the start of the path that is length units long.