This commit is contained in:
Andrej730
2025-07-09 13:47:32 +05:00
parent 40f92d15c3
commit 5a4ad69bf7
30 changed files with 362 additions and 301 deletions
@@ -18,7 +18,8 @@
import ifcopenshell.util.geolocation
def bearing2dd(bearing: str)->float:
def bearing2dd(bearing: str) -> float:
"""
Converts a quadrant bearing string to decimal degrees
@@ -35,26 +36,26 @@ def bearing2dd(bearing: str)->float:
"""
error_msg = "Invalid bearing string"
bearing = bearing.strip() # trim external white space
bearing = ' '.join(bearing.split()) # make sure all parts separated by a single space
bearing = bearing.strip() # trim external white space
bearing = " ".join(bearing.split()) # make sure all parts separated by a single space
parts = bearing.split()
nParts = len(parts)
if nParts < 3 or 5 < nParts:
raise ValueError(error_msg)
cY = parts[0]
cY = cY.upper()
if cY != 'N' and cY != 'S':
if cY != "N" and cY != "S":
raise ValueError(error_msg)
cX = parts[-1]
cX = cX.upper()
if cX != 'E' and cX != 'W':
if cX != "E" and cX != "W":
raise ValueError(error_msg)
d = 0
m = 0
s = 0.
s = 0.0
ms = 0
if nParts == 3:
@@ -69,38 +70,37 @@ def bearing2dd(bearing: str)->float:
# s in a decimal number
# need to break it into whole seconds and milliseconds
ms = 100.*(s - int(s))
ms = 100.0 * (s - int(s))
s = int(s)
if d < 0 or (m < 0 or 60 <= m) or (s < 0 or 60 <= s) or ms < 0:
raise ValueError(error_msg)
if cY == 'N' and cX == 'E':
angle = 90.
sign = -1.
elif cY == 'N' and cX == 'W':
angle = 90.
sign = 1.
elif cY == 'S' and cX == 'E':
angle = 270.
sign = 1.
elif cY == 'S' and cX == 'W':
angle = 270.
sign = -1.
if cY == "N" and cX == "E":
angle = 90.0
sign = -1.0
elif cY == "N" and cX == "W":
angle = 90.0
sign = 1.0
elif cY == "S" and cX == "E":
angle = 270.0
sign = 1.0
elif cY == "S" and cX == "W":
angle = 270.0
sign = -1.0
try:
dms = ifcopenshell.util.geolocation.dms2dd(d,m,s,ms)
dms = ifcopenshell.util.geolocation.dms2dd(d, m, s, ms)
except ValueError:
raise ValueError(error_msg)
if dms < 0. or 90. < dms:
if dms < 0.0 or 90.0 < dms:
raise ValueError(error_msg)
angle += sign*dms
angle += sign * dms
# S 90 E will evaluate to 360
if angle == 360.:
angle = 0.
if angle == 360.0:
angle = 0.0
return angle