Skip to content
Permalink
Browse files

Use QgsVectorLayerUtils.matchAttributesToFields in processing in-plac…

…e edits
  • Loading branch information
nyalldawson committed Sep 24, 2018
1 parent 95e95d0 commit 9fcd4fd00c786324eae0bfde54af14c54acc479e
Showing with 1 addition and 24 deletions.
  1. +1 −24 python/plugins/processing/gui/AlgorithmExecutor.py
@@ -91,30 +91,7 @@ def make_features_compatible(new_features, input_layer):
result_features = []
for new_f in new_features:
# Fix attributes
if new_f.fields().count() > 0:
attributes = []
for field in input_layer.fields():
if new_f.fields().indexFromName(field.name()) >= 0:
attributes.append(new_f[field.name()])
else:
attributes.append(None)
f = QgsFeature(input_layer.fields())
f.setAttributes(attributes)
f.setGeometry(new_f.geometry())
new_f = f
else:
lendiff = len(new_f.attributes()) - len(input_layer.fields())
if lendiff > 0:
f = QgsFeature(input_layer.fields())
f.setGeometry(new_f.geometry())
f.setAttributes(new_f.attributes()[:len(input_layer.fields())])
new_f = f
elif lendiff < 0:
f = QgsFeature(input_layer.fields())
f.setGeometry(new_f.geometry())
attributes = new_f.attributes() + [None for i in range(-lendiff)]
f.setAttributes(attributes)
new_f = f
QgsVectorLayerUtils.matchAttributesToFields(new_f, input_layer.fields())

# Check if we need geometry manipulation
new_f_geom_type = QgsWkbTypes.geometryType(new_f.geometry().wkbType())

0 comments on commit 9fcd4fd

Please sign in to comment.
You can’t perform that action at this time.