Skip to content
Permalink
Browse files

[processing] fix Random extract/select within subset when subset is

smaller than number of requested features (fix #19322)

(cherry-picked from 29207a1)
  • Loading branch information
alexbruy authored and nyalldawson committed Jul 4, 2018
1 parent ff6fd80 commit 5ae243079eb8c7eea7ad1254da78c83580c80796
@@ -127,7 +127,7 @@ def processAlgorithm(self, parameters, context, feedback):

for subset in classes.values():
selValue = value if method != 1 else int(round(value * len(subset), 0))
selran.extend(random.sample(subset, selValue))
selran.extend(random.sample(subset, min(selValue, len(subset))))

total = 100.0 / featureCount if featureCount else 1
for (i, feat) in enumerate(selran):
@@ -138,7 +138,7 @@ def processAlgorithm(self, parameters, context, feedback):
break

selValue = value if method != 1 else int(round(value * len(subset), 0))
selran.extend(random.sample(subset, selValue))
selran.extend(random.sample(subset, min(selValue, len(subset))))

layer.selectByIds(selran)
else:
@@ -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 5ae2430

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