Skip to content
Permalink
Browse files
[processing] prevent division by zero in save selected features
algorithm (fix #16431)
  • Loading branch information
alexbruy committed Apr 27, 2017
1 parent 459f486 commit 1ac053fc261250d475f46013dc15dd0d6e60d549
Showing with 6 additions and 2 deletions.
  1. +6 −2 python/plugins/processing/algs/qgis/SaveSelectedFeatures.py
@@ -25,8 +25,9 @@

__revision__ = '$Format:%H$'

from qgis.core import (QgsApplication)
from qgis.core import QgsApplication
from processing.core.GeoAlgorithm import GeoAlgorithm
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
from processing.core.parameters import ParameterVector
from processing.core.outputs import OutputVector
from processing.tools import dataobjects
@@ -68,7 +69,10 @@ def processAlgorithm(self, context, feedback):
writer = output.getVectorWriter(vectorLayer.fields(), vectorLayer.wkbType(), vectorLayer.crs(), context)

features = vectorLayer.getSelectedFeatures()
total = 100.0 / int(vectorLayer.selectedFeatureCount())
if len(features) == 0:
raise GeoAlgorithmExecutionException(self.tr('There are no selected features in the input layer.'))

total = 100.0 / len(features)
for current, feat in enumerate(features):
writer.addFeature(feat)
feedback.setProgress(int(current * total))

1 comment on commit 1ac053f

@vagvaf

This comment has been minimized.

Copy link

@vagvaf vagvaf commented on 1ac053f Apr 27, 2017

Hello,

thanks for your fix. I had additional thoughts about the fix but since it's my first time fixing anything I am very slow :)

Anyway, I was thinking that since this code is used for modelbuilder as well, it would be convenient to create an empty shapefile and not just raise an exception. This would be particularly helpful in batch cases.

-vagvaf

Please sign in to comment.