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 f85ff26 commit 7a09580
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions python/plugins/processing/algs/qgis/FieldsMapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 7a09580

Please sign in to comment.