Skip to content
Permalink
Browse files

[processing] log cases when subset is smaller than requested number of

features

(cherry-picked from b72f5d1)
  • Loading branch information
alexbruy authored and nyalldawson committed Jul 4, 2018
1 parent 5ae2430 commit cf73522e50c4875fc95b380da7e70d00c8fd4e2c
@@ -125,9 +125,12 @@ 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))
selran.extend(random.sample(subset, min(selValue, len(subset))))
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
for (i, feat) in enumerate(selran):
@@ -133,12 +133,15 @@ 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))
selran.extend(random.sample(subset, min(selValue, len(subset))))
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)
else:

0 comments on commit cf73522

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