From 30d62899429d4022d8659fd1ebaf6a15d63828c5 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 6 Mar 2023 17:47:22 +1100 Subject: [PATCH] New utility to quickly get the grid north or true north angles. --- .../ifcopenshell/util/geolocation.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/geolocation.py b/src/ifcopenshell-python/ifcopenshell/util/geolocation.py index 141b2e8a06..2f739ad306 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/geolocation.py +++ b/src/ifcopenshell-python/ifcopenshell/util/geolocation.py @@ -166,3 +166,24 @@ def yaxis2angle(x, y): elif angle > 180: angle -= 360 return angle + + +def get_grid_north(ifc_file): + try: + conversion = ifc_file.by_type("IfcMapConversion")[0] + except: + return 0 + if not conversion.XAxisAbscissa or not conversion.XAxisOrdinate: + return 0 + return xaxis2angle(conversion.XAxisAbscissa, conversion.XAxisOrdinate) + + +def get_true_north(ifc_file): + try: + for context in ifc_file.by_type("IfcGeometricRepresentationContext", include_subtypes=False): + if not context.TrueNorth: + continue + return yaxis2angle(*context.TrueNorth.DirectionRatios[0:2]) + except: + return 0 + return 0