1

I have two layers with same schema and same name but its contain different features.

I need to append those features with PostgreSQL db layer. All three Layers(db layer) schema and name is same .

def Transfer_data_to_Postgis(Tablayer):
  uri = QgsDataSourceUri()
  uri.setConnection(self.Hostname, self.Portid,self.Dbname,self.Username, self.Password)
  uri.setDataSource(self.Schema,Tablayer.name(),"geom","Version=1")
  dblayer= QgsVectorLayer(uri.uri(),Tablayer.name(), "postgres")
  dblayer.startEditing()
  print (dblayer.isValid())
  print (dblayer.isEditable()) 
  for fea in Tablayer.getFeatures():
      dblayer.addFeature(fea)
  dblayer.commitChanges()

Layers=QgsProject.instance().mapLayers().values() for tablay in Layers: Transfer_data_to_Postgis(tablay)

I tried above code its pushing single layer for other layer script working fine but features not appending.

What's wrong with this script and how to append features to PostGIS db layer?

Vince
  • 20,017
  • 15
  • 45
  • 64
  • Try this answer https://gis.stackexchange.com/questions/332886/copying-and-pasting-features-using-pyqgis/332912#332912 and let me know if you have any problem. Note thar you can use such plugin from Processing's GUI or call it via Python. – Germán Carrillo Nov 30 '20 at 14:27

0 Answers0