summaryrefslogtreecommitdiff
path: root/lib/utils/geometry.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-03-29 10:25:02 +0100
committerGitHub <noreply@github.com>2024-03-29 10:25:02 +0100
commit2439adafa8592995d9acead47ef2802d5d95c373 (patch)
treebfa10aaf017bc48cf6c166c7adeb9afd5dc12922 /lib/utils/geometry.py
parentfb1ecd0badf5eb142f17cc7f0f7e8b347151b002 (diff)
Add "the tartan universe" (#2782)
Diffstat (limited to 'lib/utils/geometry.py')
-rw-r--r--lib/utils/geometry.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py
index 739f9660..24cf8459 100644
--- a/lib/utils/geometry.py
+++ b/lib/utils/geometry.py
@@ -8,7 +8,7 @@ import typing
import numpy
from shapely.geometry import (GeometryCollection, LinearRing, LineString,
- MultiLineString, MultiPolygon)
+ MultiLineString, MultiPoint, MultiPolygon)
from shapely.geometry import Point as ShapelyPoint
@@ -159,6 +159,26 @@ def ensure_multi_polygon(thing, min_size=0):
return multi_polygon
+def ensure_multi_point(thing):
+ """Given a shapely geometry, return a MultiPoint"""
+ multi_point = MultiPoint()
+ if thing.is_empty:
+ return multi_point
+ if thing.geom_type == "MultiPoint":
+ return thing
+ elif thing.geom_type == "Point":
+ return MultiPoint([thing])
+ elif thing.geom_type == "GeometryCollection":
+ points = []
+ for shape in thing.geoms:
+ if shape.geom_type == "Point":
+ points.append(shape)
+ elif shape.geom_type == "MultiPoint":
+ points.extend(shape.geoms)
+ return MultiPoint(points)
+ return multi_point
+
+
def cut_path(points, length):
"""Return a subsection of at the start of the path that is length units long.