Skip to content


[processing] prevent division by zero in save selected features
Browse files Browse the repository at this point in the history
algorithm (fix #16431)
  • Loading branch information
alexbruy committed Apr 27, 2017
1 parent 459f486 commit 1ac053f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/plugins/processing/algs/qgis/
Expand Up @@ -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 import dataobjects
Expand Down Expand Up @@ -68,7 +69,10 @@ def processAlgorithm(self, context, feedback):
writer = output.getVectorWriter(vectorLayer.fields(), vectorLayer.wkbType(),, context)

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

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

1 comment on commit 1ac053f

Copy link

@vagvaf vagvaf commented on 1ac053f Apr 27, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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.


Please sign in to comment.