how to save the memory layer from QGIS in postgis database in specific schema (public) using pyqgis or python ?

here some example from my code :

outputs_QGISDIFFERENCE_1=processing.runalg('qgis:difference', layer1,layer2,False,None)
load= QgsVectorLayer(outputs_QGISDIFFERENCE_1['OUTPUT'],'myname', 'ogr')

one way is using line :

load= QgsVectorLayer(outputs_QGISDIFFERENCE_1['OUTPUT'],'myname', 'ogr')

to get the layer from algorithm.

or other way is :


to get the layer from the path.

but how to save this layer in postgis database ?


I'm not sure if you can save the output directly in PostGIS, though I'd be happy to be proved wrong. You could save the output as shp then use the shp2pgsql utility as a sub process. This question will provide the code you need to add to your python script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.