Skip to content

Commit

Permalink
Merge pull request #845 from gem/investigate-alg
Browse files Browse the repository at this point in the history
Use qgis:joinbylocationsummary in a way that works both on the python and c++ versions of the algorithm
  • Loading branch information
ptormene authored Oct 9, 2023
2 parents b37874a + 96e4d73 commit 0f4022e
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions svir/calculations/aggregate_loss_by_zone.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,19 @@ def calculate_zonal_stats(callback, zonal_layer, points_layer, join_fields,
processing.Processing.initialize()
alg = QgsApplication.processingRegistry().algorithmById(
'qgis:joinbylocationsummary')
if not isinstance(
alg, processing.algs.qgis.SpatialJoinSummary.SpatialJoinSummary):
if alg is None:
raise ImportError('Unable to retrieve processing algorithm'
' qgis:joinbylocationsummary')
# make sure to use the actual lists of predicates and summaries as defined
# in the algorithm when it is instantiated
predicate_keys = [predicate[0] for predicate in alg.predicates]
# NOTE: predicates are no more retrieavable in the c++ version of the
# algorithm, so we can't make sure to use the actual lists of predicates
# and summaries as defined in the algorithm when it is instantiated
predicate_keys = ['intersects', 'contains', 'isEqual', 'touches',
'overlaps', 'within', 'crosses']
PREDICATES = dict(zip(predicate_keys, range(len(predicate_keys))))
summary_keys = [statistic[0] for statistic in alg.statistics]
summary_keys = [
'count', 'unique', 'min', 'max', 'range', 'sum', 'mean', 'median',
'stddev', 'minority', 'majority', 'q1', 'q3', 'iqr', 'empty', 'filled',
'min_length', 'max_length', 'mean_length']
SUMMARIES = dict(zip(summary_keys, range(len(summary_keys))))

context = QgsProcessingContext()
Expand Down

0 comments on commit 0f4022e

Please sign in to comment.