Skip to content
Permalink
Browse files

[needs-docs][processing] Output count of retained and duplicate featu…

…res from

Delete duplicate geometries algorithm.

This matches the output of the delete duplicates by attribute
algorithm
  • Loading branch information
nyalldawson committed Dec 14, 2018
1 parent 82c13bd commit abc7b037d800275c07bca9c6a5c975ede7f8b993
Showing with 13 additions and 2 deletions.
  1. +13 −2 python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
@@ -30,14 +30,17 @@
QgsFeatureSink,
QgsSpatialIndex,
QgsProcessingParameterFeatureSource,
QgsProcessingParameterFeatureSink)
QgsProcessingParameterFeatureSink,
QgsProcessingOutputNumber)
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm


class DeleteDuplicateGeometries(QgisAlgorithm):

INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
RETAINED_COUNT = 'RETAINED_COUNT'
DUPLICATE_COUNT = 'DUPLICATE_COUNT'

def group(self):
return self.tr('Vector general')
@@ -56,6 +59,9 @@ def initAlgorithm(self, config=None):
self.tr('Input layer')))
self.addParameter(QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Cleaned')))

self.addOutput(QgsProcessingOutputNumber(self.RETAINED_COUNT, self.tr('Count of retained records')))
self.addOutput(QgsProcessingOutputNumber(self.DUPLICATE_COUNT, self.tr('Count of discarded duplicate records')))

def name(self):
return 'deleteduplicategeometries'

@@ -95,6 +101,7 @@ def processAlgorithm(self, parameters, context, feedback):
unique_features = dict(geoms)

current = 0
removed = 0
for feature_id, geometry in geoms.items():
if feedback.isCanceled():
break
@@ -116,6 +123,7 @@ def processAlgorithm(self, parameters, context, feedback):
if geometry.isGeosEqual(geoms[candidate_id]):
# candidate is a duplicate of feature
del unique_features[candidate_id]
removed += 1

current += 1
feedback.setProgress(int(0.80 * current * total) + 10) # takes about 80% of time
@@ -138,4 +146,7 @@ def processAlgorithm(self, parameters, context, feedback):

feedback.setProgress(int(0.10 * current * total) + 90) # takes about 10% of time

return {self.OUTPUT: dest_id}
feedback.pushInfo(self.tr('{} duplicate features removed'.format(removed)))
return {self.OUTPUT: dest_id,
self.DUPLICATE_COUNT: removed,
self.RETAINED_COUNT: len(output_feature_ids)}

0 comments on commit abc7b03

Please sign in to comment.
You can’t perform that action at this time.