2

A single postGIS table contains multiple type of spatial data(example: Linestring,Polygon,etc.,). How to load a specific spatial data from PostGIS table into QGIS by using pyqgis?


Sample code snippet is given below

uri = QgsDataSourceURI()    
uri.setConnection("xxx.xxx.xxx.xxx", "port", "dbname", "username", "password")                
uri.setDataSource("public","tablename","geom")

uri.setWkbType(QGis.WKBPolygon) #geometry type has to be mentioned

uri.setSrid('4326')
vlay=QgsVectorLayer(uri.uri(),"test_poly","postgres")
QgsMapLayerRegistry.instance().addMapLayer(vlay)
PolyGeo
  • 65,136
  • 29
  • 109
  • 338
Dharmarajan
  • 447
  • 5
  • 9

0 Answers0