I have some shapefiles. They are all the same kind of shape and all have the same attributes.
If I wanted to merge them manually the "Vector/Data management tools/merge shapefiles to one" works fine.
However, as per the question title, I'd like to do this using Python from a script.
I went hunting for the "merge shape files" in the hopes I could cobble it into my script but I couldn't find it.
I tried writing one myself iterating over the features and copying them into another layer as per the pyQGIS cookbook but lost the attributes along the way.
feature_list = inputlayer.getFeatures()
for feature in feature_list:
(res, outFeats) = outputlayer.dataProvider().addFeatures( [ feature ] )
I also tried writing a script using the iface copy features function with the same loss of attributes as a result.
qgis.utils.iface.setActiveLayer(importlayer)
importlayer.setSelectedFeatures(range(100))
#(there are exactly 100 features)
qgis.utils.iface.actionCopyFeatures().trigger()
iface.setActiveLayer( outputlayer )
outputlayer.startEditing()
qgis.utils.iface.actionPasteFeatures().trigger()
Can someone help me fix my code to retain the copied attributes or point me to a pyQGIS script to achieve this result?