|
7 | 7 | import shapely |
8 | 8 | import geopandas as gp |
9 | 9 | from ..benchmark import timer |
10 | | - |
| 10 | +import math |
| 11 | +from math import pi as PI |
11 | 12 |
|
12 | 13 | class MultiLineLayer(Layer): |
13 | 14 | @Layer.setProperty |
@@ -128,6 +129,48 @@ def getSpineSide(line: LineString, spine: Point): |
128 | 129 | val = getSide(first, last, spine) |
129 | 130 | return val |
130 | 131 |
|
| 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 | + |
131 | 174 | # abb |
132 | 175 | @ timer |
133 | 176 | def getSpinePositon(line: LineString, origin: Point): |
|
0 commit comments