Skip to content

Commit a02dffb

Browse files
committed
fix: guard against deleted QGIS layers and empty fault traces
- to_dict() crashed with RuntimeError on save if a basal contacts, fault traces, or structural orientations layer had been deleted from the project while still referenced; now caught like the existing dem_layer guard, and dem_layer_name is initialised so a caught DEM error can't leave it undefined either. - AllSampler returned a columnless DataFrame when a fault trace layer had no sampled points, causing a KeyError on 'feature_id' downstream in update_fault_points.
1 parent 09ca2ef commit a02dffb

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

loopstructural/main/data_manager.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,15 +1099,31 @@ def to_dict(self):
10991099

11001100
# Replace layer objects with layer names
11011101
if basal_contacts and 'layer' in basal_contacts and basal_contacts['layer'] is not None:
1102-
basal_contacts['layer'] = basal_contacts['layer'].name()
1102+
try:
1103+
basal_contacts['layer'] = basal_contacts['layer'].name()
1104+
except RuntimeError as e:
1105+
self.logger(message=f"Error getting basal contacts layer name: {e}", log_level=2)
1106+
basal_contacts['layer'] = None
11031107
if fault_traces and 'layer' in fault_traces and fault_traces['layer'] is not None:
1104-
fault_traces['layer'] = fault_traces['layer'].name()
1108+
try:
1109+
fault_traces['layer'] = fault_traces['layer'].name()
1110+
except RuntimeError as e:
1111+
self.logger(message=f"Error getting fault traces layer name: {e}", log_level=2)
1112+
fault_traces['layer'] = None
11051113
if (
11061114
structural_orientations
11071115
and 'layer' in structural_orientations
11081116
and structural_orientations['layer'] is not None
11091117
):
1110-
structural_orientations['layer'] = structural_orientations['layer'].name()
1118+
try:
1119+
structural_orientations['layer'] = structural_orientations['layer'].name()
1120+
except RuntimeError as e:
1121+
self.logger(
1122+
message=f"Error getting structural orientations layer name: {e}",
1123+
log_level=2,
1124+
)
1125+
structural_orientations['layer'] = None
1126+
dem_layer_name = None
11111127
if self.dem_layer is not None:
11121128
try:
11131129
dem_layer_name = self.dem_layer.name()

loopstructural/main/model_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ def __call__(self, line: gpd.GeoDataFrame, dem: Callable, use_z: bool) -> pd.Dat
9494
{'X': coords[0], 'Y': coords[1], 'Z': z, 'feature_id': feature_id, **attributes}
9595
)
9696
feature_id += 1
97+
if not points:
98+
return pd.DataFrame(points, columns=['X', 'Y', 'Z', 'feature_id'])
9799
df = pd.DataFrame(points)
98100
return df
99101

0 commit comments

Comments
 (0)