Skip to content

Commit 1ac053f

Browse files
committed
[processing] prevent division by zero in save selected features
algorithm (fix #16431)
1 parent 459f486 commit 1ac053f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

python/plugins/processing/algs/qgis/SaveSelectedFeatures.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@
2525

2626
__revision__ = '$Format:%H$'
2727

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

7071
features = vectorLayer.getSelectedFeatures()
71-
total = 100.0 / int(vectorLayer.selectedFeatureCount())
72+
if len(features) == 0:
73+
raise GeoAlgorithmExecutionException(self.tr('There are no selected features in the input layer.'))
74+
75+
total = 100.0 / len(features)
7276
for current, feat in enumerate(features):
7377
writer.addFeature(feat)
7478
feedback.setProgress(int(current * total))

0 commit comments

Comments
 (0)