Skip to content
Permalink
Browse files
Fix Refactor Fields error if layer has no features
  • Loading branch information
borysiasty committed Apr 6, 2017
1 parent f85ff26 commit 7a09580b5433de783330a4452cbf47a7d6438c2b
Showing with 29 additions and 26 deletions.
  1. +29 −26 python/plugins/processing/algs/qgis/FieldsMapper.py
@@ -117,32 +117,35 @@ def processAlgorithm(self, progress):
inFeat = QgsFeature()
outFeat = QgsFeature()
features = vector.features(layer)
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
rownum = current + 1

geometry = inFeat.geometry()
if geometry is not None:
outFeat.setGeometry(geometry)

attrs = []
for i in xrange(0, len(mapping)):
field_def = mapping[i]
expression = expressions[i]
exp_context.setFeature(inFeat)
exp_context.lastScope().setVariable("row_number", rownum)
value = expression.evaluate(exp_context)
if expression.hasEvalError():
calculationSuccess = False
error = expression.evalErrorString()
break

attrs.append(value)
outFeat.setAttributes(attrs)

writer.addFeature(outFeat)

progress.setPercentage(int(current * total))
if len(features):
total = 100.0 / len(features)
for current, inFeat in enumerate(features):
rownum = current + 1

geometry = inFeat.geometry()
if geometry is not None:
outFeat.setGeometry(geometry)

attrs = []
for i in xrange(0, len(mapping)):
field_def = mapping[i]
expression = expressions[i]
exp_context.setFeature(inFeat)
exp_context.lastScope().setVariable("row_number", rownum)
value = expression.evaluate(exp_context)
if expression.hasEvalError():
calculationSuccess = False
error = expression.evalErrorString()
break

attrs.append(value)
outFeat.setAttributes(attrs)

writer.addFeature(outFeat)

progress.setPercentage(int(current * total))
else:
progress.setPercentage(100)

del writer

0 comments on commit 7a09580

Please sign in to comment.