Skip to content

Commit 9fcd4fd

Browse files
committed
Use QgsVectorLayerUtils.matchAttributesToFields in processing in-place edits
1 parent 95e95d0 commit 9fcd4fd

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

python/plugins/processing/gui/AlgorithmExecutor.py

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -91,30 +91,7 @@ def make_features_compatible(new_features, input_layer):
9191
result_features = []
9292
for new_f in new_features:
9393
# Fix attributes
94-
if new_f.fields().count() > 0:
95-
attributes = []
96-
for field in input_layer.fields():
97-
if new_f.fields().indexFromName(field.name()) >= 0:
98-
attributes.append(new_f[field.name()])
99-
else:
100-
attributes.append(None)
101-
f = QgsFeature(input_layer.fields())
102-
f.setAttributes(attributes)
103-
f.setGeometry(new_f.geometry())
104-
new_f = f
105-
else:
106-
lendiff = len(new_f.attributes()) - len(input_layer.fields())
107-
if lendiff > 0:
108-
f = QgsFeature(input_layer.fields())
109-
f.setGeometry(new_f.geometry())
110-
f.setAttributes(new_f.attributes()[:len(input_layer.fields())])
111-
new_f = f
112-
elif lendiff < 0:
113-
f = QgsFeature(input_layer.fields())
114-
f.setGeometry(new_f.geometry())
115-
attributes = new_f.attributes() + [None for i in range(-lendiff)]
116-
f.setAttributes(attributes)
117-
new_f = f
94+
QgsVectorLayerUtils.matchAttributesToFields(new_f, input_layer.fields())
11895

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

0 commit comments

Comments
 (0)