Tuesday 26 July 2016

qgis - Load a specific spatial data from a postGIS table


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)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...