Skip to content

Commit

Permalink
Dissolve only once instead of for every value
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 committed Jul 31, 2023
1 parent 2f426c9 commit 1cecd3c
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions pzp_utils/processing/danger_zones.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,31 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.pushInfo(f"Used matrix values {used_matrix_values}")
feedback.pushInfo(f"Process sources {process_sources}")

result = processing.run(
"native:dissolve",
{
"INPUT": parameters[self.INPUT],
"FIELD": f"{matrix_field}",
"SEPARATE_DISJOINT": True,
"OUTPUT": "memory:",
},
context=context,
feedback=feedback,
is_child_algorithm=True,
)
input_layer = result["OUTPUT"]

final_layer = None
for process_source in process_sources:
result = self.prepare_process_source(
used_matrix_values, process_source, matrix_field, process_source_field, parameters, context, feedback
input_layer,
used_matrix_values,
process_source,
matrix_field,
process_source_field,
parameters,
context,
feedback,
)

if final_layer:
Expand All @@ -132,7 +153,15 @@ def processAlgorithm(self, parameters, context, feedback):
return {self.OUTPUT: final_layer}

def prepare_process_source(
self, used_matrix_values, process_source, matrix_field, process_source_field, parameters, context, feedback
self,
input_layer,
used_matrix_values,
process_source,
matrix_field,
process_source_field,
parameters,
context,
feedback,
):
# Escape ' in process_source
process_source = process_source.replace("'", "''")
Expand All @@ -143,7 +172,7 @@ def prepare_process_source(
result = processing.run(
"native:extractbyexpression",
{
"INPUT": parameters[self.INPUT],
"INPUT": input_layer,
"EXPRESSION": f'"{matrix_field}" = {matrix_value} AND "{process_source_field}" = \'{process_source}\'',
"OUTPUT": "memory:",
},
Expand Down

0 comments on commit 1cecd3c

Please sign in to comment.