6

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

whyzar
12.1k23 gold badges41 silver badges72 bronze badges
asked Oct 9, 2017 at 20:08
0

1 Answer 1

2

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.

answered Oct 9, 2017 at 20:56
1
  • Thank you for your reaction. I just solved my probem. I had to split name of table "okresy" and "originalnihranice". Commented Oct 10, 2017 at 15:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.