I am writing a plugin for QGIS 3.8
I have two layers,
- drop_layer and
- Fibre Cable.
I want to copy all features from the drop_layer and append to Fibre cable layer.
I use a function to create drop_layer using some processing tools. Then I use following function merge_to_original_Fibre_layer
to copy all features of this "drop_layer" to another existing layer "Fibre cable". All these functions are part of the main class.
def merge_to_original_Fibre_layer(self):
dlayer = self.drop_layer.getFeatures()
layerObject = QgsProject.instance().mapLayersByName("Fibre Cable")[0]
features = []
for f in dlayer:
features.append(f)
layerObject.startEditing()
layerObject.addFeatures(features)
layerObject.commitChanges()
When I run the code, all the features of "drop_layer" are getting copied to "Fibre Cable" layer. I see this when I open the attribute table of the layer "Fibre Cable". Even I am able to zoom map to these features.
The problem is I cannot see the geometry of these newly added features on the map. What I am doing wrong?
layerObject.updateExtents()
.layerObject.dataProvider().addFeatures(features)