Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[processing] fix Random extract/select within subset when subset is
smaller than number of requested features (fix #19322)
  • Loading branch information
alexbruy committed Jul 4, 2018
1 parent d66d1ee commit 29207a1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Expand Up @@ -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):
Expand Down
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions python/plugins/processing/tests/testdata/qgis_algorithm_tests.yaml
Expand Up @@ -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:
Expand Down Expand Up @@ -5355,6 +5370,7 @@ tests:
compare:
fields:
fid: skip

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

0 comments on commit 29207a1

Please sign in to comment.