mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Converting project length units now intelligently preserves map unit and coordinate operation scale.
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
import test.bootstrap
|
||||
import ifcopenshell.api.unit
|
||||
import ifcopenshell.api.root
|
||||
import ifcopenshell.api.georeference
|
||||
import ifcopenshell.util.geolocation
|
||||
import ifcopenshell.util.unit as subject
|
||||
from math import pi
|
||||
|
||||
@@ -92,3 +94,73 @@ class TestIsAttrType(test.bootstrap.IFC4):
|
||||
assert subject.is_attr_type(nominal_value, "IfcValue")
|
||||
assert subject.is_attr_type(nominal_value, "IfcLengthMeasure")
|
||||
assert not subject.is_attr_type(nominal_value, "IfcLengthMeasure", include_select_types=False)
|
||||
|
||||
|
||||
class TestConvertFileLengthUnits(test.bootstrap.IFC4):
|
||||
def test_run(self):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
|
||||
output = subject.convert_file_length_units(self.file, target_units="METER")
|
||||
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "METRE"
|
||||
|
||||
def test_converting_map_conversion_if_there_is_no_map_unit(self):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
ifcopenshell.api.context.add_context(self.file, "Model")
|
||||
ifcopenshell.api.georeference.add_georeferencing(self.file)
|
||||
ifcopenshell.api.georeference.edit_georeferencing(self.file, coordinate_operation={"Eastings": 10000})
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
|
||||
output = subject.convert_file_length_units(self.file, target_units="METER")
|
||||
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "METRE"
|
||||
assert output.by_type("IfcMapConversion")[0].Eastings == 10
|
||||
|
||||
def test_preserving_enh_if_there_is_a_map_unit(self):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
meter = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
|
||||
ifcopenshell.api.context.add_context(self.file, "Model")
|
||||
ifcopenshell.api.georeference.add_georeferencing(self.file)
|
||||
ifcopenshell.api.georeference.edit_georeferencing(
|
||||
self.file, projected_crs={"MapUnit": meter}, coordinate_operation={"Eastings": 10, "Scale": 0.001}
|
||||
)
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
|
||||
output = subject.convert_file_length_units(self.file, target_units="METER")
|
||||
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "METRE"
|
||||
assert output.by_type("IfcMapConversion")[0].Eastings == 10
|
||||
assert output.by_type("IfcMapConversion")[0].Northings == 0
|
||||
assert output.by_type("IfcMapConversion")[0].Scale == 1
|
||||
assert subject.get_full_unit_name(output.by_type("IfcProjectedCRS")[0].MapUnit) == "METRE"
|
||||
|
||||
|
||||
class TestConvertFileLengthUnitsIFC2X3(test.bootstrap.IFC2X3):
|
||||
def test_converting_map_conversion_if_there_is_no_map_unit(self):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
ifcopenshell.api.context.add_context(self.file, "Model")
|
||||
ifcopenshell.api.georeference.add_georeferencing(self.file)
|
||||
ifcopenshell.api.georeference.edit_georeferencing(self.file, coordinate_operation={"Eastings": 10000})
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
|
||||
output = subject.convert_file_length_units(self.file, target_units="METER")
|
||||
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "METRE"
|
||||
parameters = ifcopenshell.util.geolocation.get_helmert_transformation_parameters(output)
|
||||
assert parameters.e == 10
|
||||
|
||||
def test_preserving_enh_if_there_is_a_map_unit(self):
|
||||
ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcProject")
|
||||
unit = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT", prefix="MILLI")
|
||||
meter = ifcopenshell.api.unit.add_si_unit(self.file, unit_type="LENGTHUNIT")
|
||||
ifcopenshell.api.context.add_context(self.file, "Model")
|
||||
ifcopenshell.api.georeference.add_georeferencing(self.file)
|
||||
ifcopenshell.api.georeference.edit_georeferencing(
|
||||
self.file, projected_crs={"MapUnit": subject.get_full_unit_name(meter)}, coordinate_operation={"Eastings": 10, "Scale": 0.001}
|
||||
)
|
||||
ifcopenshell.api.unit.assign_unit(self.file, units=[unit])
|
||||
output = subject.convert_file_length_units(self.file, target_units="METER")
|
||||
assert subject.get_full_unit_name(subject.get_project_unit(output, "LENGTHUNIT")) == "METRE"
|
||||
parameters = ifcopenshell.util.geolocation.get_helmert_transformation_parameters(output)
|
||||
assert parameters.e == 10
|
||||
assert parameters.n == 0
|
||||
assert parameters.scale == 1
|
||||
crs = ifcopenshell.util.element.get_pset(output.by_type("IfcProject")[0], name="ePSet_ProjectedCRS")
|
||||
assert crs["MapUnit"] == "METRE"
|
||||
|
||||
Reference in New Issue
Block a user