From 555fb065e90d4ae31a54231d2bc3bafd4a557b34 Mon Sep 17 00:00:00 2001 From: Tim Sutton Date: Thu, 2 Jan 2025 21:44:20 +0000 Subject: [PATCH] Soft code mask mode type --- .../opportunities_polygon_mask_workflow.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/geest/core/workflows/opportunities_polygon_mask_workflow.py b/geest/core/workflows/opportunities_polygon_mask_workflow.py index 5395e15..114b08a 100644 --- a/geest/core/workflows/opportunities_polygon_mask_workflow.py +++ b/geest/core/workflows/opportunities_polygon_mask_workflow.py @@ -69,27 +69,40 @@ def __init__( working_directory=working_directory, ) # ⭐️ Item is a reference - whatever you change in this item will directly update the tree self.workflow_name = "opportunities_polygon_mask" + + self.mask_mode = self.attributes.get( + "mask_mode", None + ) # if set, will be "point", "polygon" or "raster" + if not self.mask_mode: + raise Exception("Mask mode not set in the analysis.") + # There are two ways a user can specify the polygon mask layer # either as a shapefile path added in a line edit or as a layer source # using a QgsMapLayerComboBox. We prioritize the shapefile path, so check that first. - layer_source = self.attributes.get("polygon_mask_shapefile", None) + layer_source = self.attributes.get(f"{self.mask_mode}_mask_shapefile", None) provider_type = "ogr" if not layer_source: # Fall back to the QgsMapLayerComboBox source - layer_source = self.attributes.get("polygon_mask_layer_source", None) + layer_source = self.attributes.get( + f"{self.mask_mode}_mask_layer_source", None + ) provider_type = self.attributes.get( - "polygon_mask_layer_provider_type", "ogr" + f"{self.mask_mode}_mask_layer_provider_type", "ogr" ) if not layer_source: log_message( - "polygon_mask_shapefile not found", + f"{self.mask_mode}_mask_shapefile not found", tag="Geest", level=Qgis.Critical, ) return False - self.features_layer = QgsVectorLayer(layer_source, "polygons", provider_type) + self.features_layer = QgsVectorLayer( + layer_source, self.mask_mode, provider_type + ) if not self.features_layer.isValid(): - log_message("polygon_mask_shapefile not valid", level=Qgis.Critical) + log_message( + f"{self.mask_mode}_mask_shapefile not valid", level=Qgis.Critical + ) log_message(f"Layer Source: {layer_source}", level=Qgis.Critical) return False @@ -103,10 +116,6 @@ def __init__( self.result_file_key = "opportunities_mask_result_file" self.result_key = "opportunities_mask_result" - self.mask_mode = self.attributes.get("mask_mode", None) - if not self.mask_mode: - raise Exception("Mask mode not set in the analysis.") - # Section below to be removed # These folders should already exist from the aggregation analysis and population raster processing