diff options
| author | Lex Neva <github.com@lexneva.name> | 2022-04-30 15:21:13 -0400 |
|---|---|---|
| committer | Kaalleen <reni@allenka.de> | 2022-05-04 19:18:33 +0200 |
| commit | e14fffb879875cae43124a7daae7cebb5bcadddc (patch) | |
| tree | b69c40e32337a7af2cc610937215fd18a8d6ddf8 /lib/utils/geometry.py | |
| parent | ff0aa68876c5b6840a5d7f01ef2af6c848190570 (diff) | |
remove redundant cut() function
Diffstat (limited to 'lib/utils/geometry.py')
| -rw-r--r-- | lib/utils/geometry.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/utils/geometry.py b/lib/utils/geometry.py index bce278ed..ed1e2c0e 100644 --- a/lib/utils/geometry.py +++ b/lib/utils/geometry.py @@ -5,7 +5,7 @@ import math -from shapely.geometry import LineString +from shapely.geometry import LineString, LinearRing from shapely.geometry import Point as ShapelyPoint @@ -39,6 +39,33 @@ def cut(line, distance, normalized=False): LineString([(cp.x, cp.y)] + coords[i:])] +def roll_linear_ring(ring, distance, normalized=False): + """Make a linear ring start at a different point. + + Example: A B C D E F G A -> D E F G A B C + + Same linear ring, different ordering of the coordinates. + """ + + if not isinstance(ring, LinearRing): + # In case they handed us a LineString + ring = LinearRing(ring) + + pieces = cut(LinearRing(ring), distance, normalized=False) + + if None in pieces: + # We cut exactly at the start or end. + return ring + + # The first and last point in a linear ring are duplicated, so we omit one + # copy + return LinearRing(pieces[1].coords[:] + pieces[0].coords[1:]) + + +def reverse_line_string(line_string): + return LineString(line_string.coords[::-1]) + + def cut_path(points, length): """Return a subsection of at the start of the path that is length units long. |
