I'm quite new to PyQGIS and have what is probably a pretty basic question, but I haven't been able to pick it up from the documentation. I have a QgsVectorLayer object from a PostGIS server, and I want to render it in the Map Canvas. How do I go from vector layer object to rendered map?


1 Answer 1


As with the other vector layers:

uri = QgsDataSourceURI()
uri.setConnection("localhost", "5432", "your_database", "you", "password")
uri.setDataSource("public", "your_table", "the_geom")
vlayer = QgsVectorLayer(uri.uri(), "name_of_layer_in_the_canvas", "postgres")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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