Skip to content
Permalink
Browse files

[processing] Fix random selection algorithm when filter is set on layer

  • Loading branch information
nyalldawson committed Jun 28, 2018
1 parent 977e14b commit 31330ddffb67a15adceafe85d627bbb2d9a3ae4d
Showing with 4 additions and 4 deletions.
  1. +4 −4 python/plugins/processing/algs/qgis/RandomSelection.py
@@ -93,11 +93,11 @@ def processAlgorithm(self, parameters, context, feedback):
layer = self.parameterAsVectorLayer(parameters, self.INPUT, context)
method = self.parameterAsEnum(parameters, self.METHOD, context)

featureCount = layer.featureCount()
ids = layer.allFeatureIds()
value = self.parameterAsInt(parameters, self.NUMBER, context)

if method == 0:
if value > featureCount:
if value > len(ids):
raise QgsProcessingException(
self.tr('Selected number is greater than feature count. '
'Choose a lower value and try again.'))
@@ -106,9 +106,9 @@ def processAlgorithm(self, parameters, context, feedback):
raise QgsProcessingException(
self.tr("Percentage can't be greater than 100. Set a "
"different value and try again."))
value = int(round(value / 100.0, 4) * featureCount)
value = int(round(value / 100.0, 4) * len(ids))

selran = random.sample(list(range(featureCount)), value)
selran = random.sample(ids, value)

layer.selectByIds(selran)
return {self.OUTPUT: parameters[self.INPUT]}

0 comments on commit 31330dd

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