Skip to content
Permalink
Browse files

Merge pull request #7363 from alexbruy/fix-sampling

[processing] fix Random extract/select within subset algorithms
  • Loading branch information
alexbruy committed Jul 4, 2018
2 parents 6c014b4 + b72f5d1 commit 6d751dcb70b97b9972b4f893f156048a77aca7f8
@@ -125,8 +125,11 @@ def processAlgorithm(self, parameters, context, feedback):
classes[attrs[index]].append(feature)
feedback.setProgress(int(i * total))

for subset in classes.values():
for k, subset in classes.items():
selValue = value if method != 1 else int(round(value * len(subset), 0))
if selValue > len(subset):
selValue = len(subset)
feedback.reportError(self.tr('Subset "{}" is smaller than requested number of features.'.format(k)))
selran.extend(random.sample(subset, selValue))

total = 100.0 / featureCount if featureCount else 1
@@ -133,11 +133,14 @@ def processAlgorithm(self, parameters, context, feedback):
feedback.setProgress(int(i * total))

selran = []
for subset in classes.values():
for k, subset in classes.items():
if feedback.isCanceled():
break

selValue = value if method != 1 else int(round(value * len(subset), 0))
if selValue > len(subset):
selValue = len(subset)
feedback.reportError(self.tr('Subset "{}" is smaller than requested number of features.'.format(k)))
selran.extend(random.sample(subset, selValue))

layer.selectByIds(selran)
@@ -3923,6 +3923,21 @@ tests:
name: points_weighted.gml
compare: false

- algorithm: qgis:randomextractwithinsubsets
name: Random extract within subset (subset smaller than number)
params:
FIELD: id2
INPUT:
name: points.gml
type: vector
METHOD: 0
NUMBER: 3
results:
OUTPUT:
type: vector
name: points.gml
compare: false

- algorithm: qgis:heatmapkerneldensityestimation
name: Heatmap (Kernel density estimation)
params:
@@ -5355,6 +5370,7 @@ tests:
compare:
fields:
fid: skip

- algorithm: native:difference
name: Test Difference B - A (basic)
params:

0 comments on commit 6d751dc

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