I want to add new layer from PostGIS database but this code isn't working... Can someone help me?
uri = QgsDataSourceURI()
uri.setConnection("IP address", "5432", "ruian", "user", "pass", QgsDataSourceURI.SSLdisable)
uri.setDataSource("public", "okresy.originalnihranice", "MultiPolygon", "", "ogc_fid")
layer = QgsVectorLayer(uri.uri(), "okresy", "postgres")
if not layer.isValid():
print "Layer %s did not load" % layer.name()
QgsMapLayerRegistry.instance().addMapLayers([layer])
layer is always empty
1 Answer 1
I would suggest looking into this post Empty layer after import into PostGIS Database. Pyqgis
The user mentioned to
make sure that you are looking at using
psycopg2
python module. This should have been installed when you got PostgreSQL and PostGIS in your system.created my new user with privileges of superuser for being able to add postgis extension in new database
use pgadmin3 to create a new connection and to add postgis extension to this database.
-
Thank you for your reaction. I just solved my probem. I had to split name of table "okresy" and "originalnihranice".Miroslav Starý– Miroslav Starý2017年10月10日 15:53:39 +00:00Commented Oct 10, 2017 at 15:53
Explore related questions
See similar questions with these tags.