0

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?

Thanks!

0

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")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

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.