Skip to content

Commit 55e85a6

Browse files
committed
Adding spine line angle relative to segment
1 parent 795ff14 commit 55e85a6

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

mapmanagercore/layers/line.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import shapely
88
import geopandas as gp
99
from ..benchmark import timer
10-
10+
import math
11+
from math import pi as PI
1112

1213
class MultiLineLayer(Layer):
1314
@Layer.setProperty
@@ -128,6 +129,48 @@ def getSpineSide(line: LineString, spine: Point):
128129
val = getSide(first, last, spine)
129130
return val
130131

132+
# abj
133+
@ timer
134+
def getSpineAngle(segmentLine: LineString, spineLine: LineString):
135+
""" Return the angle between the two Lines
136+
Line 1: The line formed between the spine head and the anchor point
137+
Line 2: The line formed by two points on the segment tracing.
138+
Grab two points, one “up” and the other “down” the segment from the spine anchor point.
139+
I think the anchor point on the segment tracing is our new “position”.
140+
141+
Args:
142+
segmentLine: segment in the for of a LineString
143+
spineLine: Linestring of spine head to anchor point
144+
"""
145+
spineLineCoord0 = Point(spineLine.coords[0])
146+
spineLineCoord1 = Point(spineLine.coords[1])
147+
sl0x = spineLineCoord0.x
148+
sl0y = spineLineCoord0.y
149+
sl1x = spineLineCoord1.x
150+
sl1y = spineLineCoord1.y
151+
152+
segmentLineCoord0 = Point(segmentLine.coords[0])
153+
segmentLineCoord1 = Point(segmentLine.coords[-1])
154+
sgl0x = segmentLineCoord0.x
155+
sgl0y = segmentLineCoord0.y
156+
sgl1x = segmentLineCoord1.x
157+
sgl1y = segmentLineCoord1.y
158+
159+
m1 = (sl1y-sl0y)/(sl1x-sl0x)
160+
m2 = (sgl1y-sgl0y)/(sgl1x-sgl0x)
161+
162+
angle_rad = math.atan(m1) - math.atan(m2)
163+
angle_deg = angle_rad*180/PI
164+
165+
# Range: 0 - 360
166+
# Check for Negative angle and add 360 degrees to determine counter clockwise value
167+
if angle_deg < 0:
168+
angle_deg = angle_deg + 360
169+
170+
# print("m1", m1, "m2", m2, "degree:", angle_deg)
171+
172+
return angle_deg
173+
131174
# abb
132175
@ timer
133176
def getSpinePositon(line: LineString, origin: Point):

mapmanagercore/schemas/spine.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from shapely.geometry import Point
22
import numpy as np
3-
from ..layers.line import calcSubLine, extend, getSpinePositon, getSpineSide
3+
from ..layers.line import calcSubLine, extend, getSpinePositon, getSpineSide, getSpineAngle
44
import shapely
55
from ..lazy_geo_pandas import schema, calculated, LazyGeoFrame
66
import geopandas as gp
@@ -114,6 +114,7 @@ class Spine:
114114
segmentID: int
115115
point: Point
116116
anchor: Point
117+
spineAngle: LineString
117118

118119
xBackgroundOffset: float
119120
yBackgroundOffset: float
@@ -175,6 +176,21 @@ def spineSide(frame: LazyGeoFrame):
175176
@calculated(title="Anchor", dependencies=["anchor", "point"], plot=False)
176177
def anchorLine(frame: LazyGeoFrame):
177178
return frame[["anchor", "point"]].apply(lambda x: LineString([x["anchor"], x["point"]]), axis=1)
179+
180+
# abj
181+
@calculated(title="Spine Angle", dependencies=["point"])
182+
def angle(frame: LazyGeoFrame):
183+
184+
# do this for all spines
185+
segmentFrame = frame.getFrame("Segment")
186+
df = frame[["segmentID", "point", "anchorLine"]].join(
187+
segmentFrame[["segment"]], on=["segmentID", "t"])
188+
print("spineAngle df:", df)
189+
190+
# # Create a dataframe of
191+
_ret = df.apply(lambda d: getSpineAngle(d["segment"], d["anchorLine"]), axis=1)
192+
193+
return _ret
178194

179195
@calculated(tile="ROI Base", dependencies={
180196
"Spine": ["anchor"],

0 commit comments

Comments
 (0)