Alignment api update (#6817)

* Some basic COGO survey points functions

* Update alignment api

Includes defining alignment segment by segment, automatic geometry definitions, and automatric stationing and referents

* Fixes bonsai import alignment from csv

* Adds DMS angle conversion functions to COGO api

* Updated per @civilx64 review comments

* Fixes problem with segment representations

* Fixes problem with segment transition codes

* Allows for compound vertical and horizontal curves

* Implements callbacks for referent naming

* Renames angle_from_bearing to bearing2dd for consistency with ifcopenshell.util.geolocation.dms2dd. Removes angle_from_dms because it duplicates dms2dd

* Documents register_referent_name_callback

* Fixes all sorts of problems with Cant/SegRefCurve implementation

* refactor referent unit tests to use a fixture for test setup

* lint with black

---------

Co-authored-by: Scott Lecher <civilx64@gmail.com>
This commit is contained in:
Richard Brice
2025-07-08 10:09:14 -07:00
committed by GitHub
parent ad8d02bfed
commit 40f92d15c3
76 changed files with 3645 additions and 1839 deletions
@@ -17,15 +17,29 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import math
import ifcopenshell
import ifcopenshell.util.unit
def station_as_string(file: ifcopenshell.file, sta: float):
"""
Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string.
If the project units are SI-based, the string is in the format xxx+yyy.zzz
If the project units are Emperial-based, the string is in the format xx+yy.zz
:param station: the station to be stringized
:return: stringized station
"""
unit_type = ifcopenshell.util.unit.get_project_unit(file,"LENGTHUNIT")
if unit_type.is_a("IfcConversionBasedUnit"):
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=None,to_unit="foot",to_prefix=None)
plus_seperator = 2
precision = 2
else:
station = ifcopenshell.util.unit.convert(sta,from_unit=unit_type.Name,from_prefix=unit_type.Prefix,to_unit="meter",to_prefix=None)
plus_seperator = 3
precision = 3
def station_as_string(station: float, plus_seperator=3, accuracy=3):
"""
Returns a stringized version of a station. Example 100.0 is 1+00.00 as a stationing string
@param station: the station to be stringized
@param plus_seperator: location of the '+' symbol relative to the decimal place (typically 2 for US units and 3 for SI units)
@param accuracy: number of digits following the decimal place
"""
value = math.fabs(station)
shifter = math.pow(10.0, plus_seperator)
@@ -34,13 +48,13 @@ def station_as_string(station: float, plus_seperator=3, accuracy=3):
# Check to make sure that v2 is not basically the same as shifter
# If station = 69500.00000, we sometimes get 694+100.00 instead of 695+00.00
if math.isclose(v2 - shifter, 5.0 * math.pow(10.0, -(accuracy + 1))):
if math.isclose(v2-shifter, 0., abs_tol=5.0 * math.pow(10.0, -(precision + 1))):
v2 = 0.0
v1 += 1
v1 = -1 * v1 if station < 0 else v1
station_string = "{:d}+{:0{}.{}f}".format(v1, v2, plus_seperator + accuracy + 1, accuracy)
station_string = "{:d}+{:0{}.{}f}".format(v1, v2, plus_seperator + precision + 1, precision)
# special case when v1 is 0 and station is negative, the string above doesn't get the leading
# negative sign. this snippet fixes that