Fix add_georeferencing silently failing with orphan CRS or conversion

If a file had an IfcProjectedCRS without an IfcCoordinateOperation (or
vice versa), add_georeferencing would return early without creating the
missing entity. This caused edit_georeferencing to crash with IndexError.
Now detects the inconsistent state, cleans up, and recreates both.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-03-25 14:57:10 +11:00
parent db68195310
commit 611273a20a
2 changed files with 31 additions and 1 deletions
@@ -17,6 +17,7 @@
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
import ifcopenshell.api.georeference
import ifcopenshell.api.pset
import ifcopenshell.util.element
@@ -63,8 +64,13 @@ def add_georeferencing(file: ifcopenshell.file, ifc_class: str = "IfcMapConversi
},
)
return
if file.by_type("IfcProjectedCRS"):
has_crs = bool(file.by_type("IfcProjectedCRS"))
has_conversion = bool(file.by_type("IfcCoordinateOperation"))
if has_crs and has_conversion:
return
if has_crs or has_conversion:
# This is technically invalid, but we shall forgive the industry here if they are wrong ...
ifcopenshell.api.georeference.remove_georeferencing(file)
source_crs = None
for context in file.by_type("IfcGeometricRepresentationContext", include_subtypes=False):
if context.ContextType == "Model":