Skip to content

Commit

Permalink
Fix Refactor Fields error if layer has no features
Browse files Browse the repository at this point in the history
  • Loading branch information
borysiasty committed Apr 6, 2017
1 parent c32c9e3 commit 323af15
Showing 1 changed file with 27 additions and 24 deletions.
51 changes: 27 additions & 24 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 323af15

Please sign in to comment.