Skip to content

Commit 1142c52

Browse files
committed
Geolocation util can now apply georeferencing to matrices
1 parent ea52476 commit 1142c52

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

src/ifcopenshell-python/ifcopenshell/util/geolocation.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import math
2+
import numpy as np
23

34

45
def dms2dd(degrees, minutes, seconds, ms=0):
@@ -45,6 +46,54 @@ def enh2xyz(e, n, h, eastings, northings, orthogonal_height, x_axis_abscissa, x_
4546
return (x, y, z)
4647

4748

49+
def local2global(matrix, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None):
50+
if scale is None:
51+
scale = 1.0
52+
x = np.array([x_axis_abscissa, x_axis_ordinate, 0])
53+
x /= np.linalg.norm(x)
54+
y = np.cross(np.array([0, 0, 1]), x)
55+
intermediate = (
56+
np.matrix(
57+
[
58+
[x[0], y[0], 0, 0],
59+
[x[1], y[1], 0, 0],
60+
[x[2], y[2], 1, 0],
61+
[0, 0, 0, 1],
62+
]
63+
)
64+
@ matrix
65+
)
66+
intermediate[0, 3] = (intermediate[0, 3] * scale) + eastings
67+
intermediate[1, 3] = (intermediate[1, 3] * scale) + northings
68+
intermediate[2, 3] = (intermediate[2, 3] * scale) + orthogonal_height
69+
return intermediate
70+
71+
72+
def global2local(matrix, eastings, northings, orthogonal_height, x_axis_abscissa, x_axis_ordinate, scale=None):
73+
if scale is None:
74+
scale = 1.0
75+
x = np.array([x_axis_abscissa, x_axis_ordinate, 0])
76+
x /= np.linalg.norm(x)
77+
y = np.cross(np.array([0, 0, 1]), x)
78+
result = matrix.copy()
79+
result[0, 3] = (result[0, 3] - eastings) / scale
80+
result[1, 3] = (result[1, 3] - northings) / scale
81+
result[2, 3] = (result[2, 3] - orthogonal_height) / scale
82+
return (
83+
np.linalg.inv(
84+
np.matrix(
85+
[
86+
[x[0], y[0], 0, 0],
87+
[x[1], y[1], 0, 0],
88+
[x[2], y[2], 1, 0],
89+
[0, 0, 0, 1],
90+
]
91+
)
92+
)
93+
@ result
94+
)
95+
96+
4897
# Used for converting the X and Y vectors of the X Axis in IFC geolocation
4998
def xy2angle(x, y):
5099
return math.degrees(math.atan2(y, x))

0 commit comments

Comments
 (0)