mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
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:
@@ -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":
|
||||
|
||||
Reference in New Issue
Block a user