Files
IfcOpenShell/src/ifcopenshell-python/ifcopenshell/util/geolocation.py
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

51 lines
1.7 KiB
Python
Raw Normal View History

2020-05-17 12:20:36 +02:00
import math
2020-11-01 20:08:27 +07:00
def dms2dd(degrees, minutes, seconds, ms=0):
2020-11-01 20:08:27 +07:00
dd = float(degrees) + float(minutes) / 60.0 + float(seconds) / (3600.0) + float(ms / 3600000000.0)
return dd
2020-11-01 20:08:27 +07:00
def dd2dms(dd, use_ms=False):
dd = float(dd)
sign = 1 if dd >= 0 else -1
dd = abs(dd)
if use_ms:
2020-11-01 20:08:27 +07:00
seconds, ms = divmod(dd * 60 * 60 * 1000000, 1000000)
minutes, seconds = divmod(dd * 60 * 60, 60)
degrees, minutes = divmod(minutes, 60)
if dd < 0:
degrees = -degrees
if use_ms:
return (int(degrees) * sign, int(minutes) * sign, int(seconds) * sign, int(ms) * sign)
return (int(degrees) * sign, int(minutes) * sign, int(seconds) * sign)
2020-11-01 20:08:27 +07:00
def xyz2enh(x, y, z, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None):
if scale is None:
2020-11-01 20:08:27 +07:00
scale = 1.0
2020-05-17 12:20:36 +02:00
rotation = math.atan2(x_axis_ordinate, x_axis_abscissa)
a = scale * math.cos(rotation)
b = scale * math.sin(rotation)
eastings = (a * x) - (b * y) + eastings
northings = (b * x) + (a * y) + northings
height = z + orthogonal_height
return (eastings, northings, height)
2020-11-01 20:08:27 +07:00
def enh2xyz(e, n, h, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None):
if scale is None:
scale = 1.0
rotation = math.atan2(x_axis_ordinate, x_axis_abscissa)
a = scale * math.cos(rotation)
b = scale * math.sin(rotation)
x = ((b * n) - (b * northings) - (a * eastings) + (a * e)) / ((a * a) + (b * b))
y = ((a * n) - (a * northings) + (b * eastings) - (b * e)) / ((a * a) + (b * b))
z = h - orthogonal_height
return (x, y, z)
# Used for converting the X and Y vectors of the X Axis in IFC geolocation
def xy2angle(x, y):
return math.degrees(math.atan2(y, x))