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 c32c9e3 commit 323af157a97cc289226df8fb58b7da3a183db743
Showing with 27 additions and 24 deletions.
  1. +27 −24 python/plugins/processing/algs/qgis/FieldsMapper.py
@@ -115,30 +115,33 @@ 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

outFeat.setGeometry(inFeat.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

outFeat.setGeometry(inFeat.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 323af15

Please sign in to comment.