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

smaller than number of requested features (fix #19322)
This commit is contained in:
Alexander Bruy 2018-07-04 18:30:30 +03:00
parent d66d1eec1b
commit 29207a1617
3 changed files with 18 additions and 2 deletions

View File

@ -127,7 +127,7 @@ class RandomExtractWithinSubsets(QgisAlgorithm):
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):

View File

@ -138,7 +138,7 @@ class RandomSelectionWithinSubsets(QgisAlgorithm):
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:

View File

@ -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: