Skip to content

Commit

Permalink
[needs-docs][processing] Output count of retained and duplicate featu…
Browse files Browse the repository at this point in the history
…res from

Delete duplicate geometries algorithm.

This matches the output of the delete duplicates by attribute
algorithm
  • Loading branch information
nyalldawson committed Dec 15, 2018
1 parent 82c13bd commit abc7b03
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions python/plugins/processing/algs/qgis/DeleteDuplicateGeometries.py
Expand Up @@ -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')
Expand All @@ -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'

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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.