Skip to main content
Bumped by Community user
deleted 5 characters in body
Source Link
Kadir Şahbaz
  • 78k
  • 57
  • 257
  • 404

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 iI use following function "merge_to_original_Fibre_layer"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 iI 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 iI am able to zoom map to these features.

The problem is i can not see the geometry of these newly added features on the map. What I am doing wrong? The problem is I cannot see the geometry of these newly added features on the map. What I am doing wrong?

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 can not see the geometry of these newly added features on the map. What I am doing wrong?

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?

Source Link

Copying features from one layer into another in PyQGIS using addFeatures

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 can not see the geometry of these newly added features on the map. What I am doing wrong?