[QGIS-Developer] change the datasource of a vector layer in pyqgis

Bruno Streit brunos at mailbox.org
Tue Aug 6 03:36:09 PDT 2024


Dear list
 
I want to change the datasource of some layers with a qgis plugin. It is a change from gdb to postgres. I am checking the new source in a testlayer:
 
print(layer.source()) returns:
old: //zihl/grundlagen/1_GeodatenLV95/2_Kanton_Bern/AGI/A_AV_admin/MOPUBE/data/MOPUBE.gdb|layername=MOPUBE_LIF
 
print(testlayer.source()) returns:
dbname='be' service='be' key='id' checkPrimaryKeyUnicity='1' table="AGI-MOPUBE"."MOPUBE_LIF" (geom)
 
How can I set the datasource of layer to the one of testlayer?
Do i need layer.setDatasource() or layer.setDataProvider() ?
 
Could anyone provide an example?
Any help is apprecaited.
Thanks
Bruno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20240806/a5c30719/attachment.htm>


More information about the QGIS-Developer mailing list