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)
1
  • 1
    did you try something like select * from table where ST_GeometryType(thegeomcolumn)='ST_Linestring'? Commented Jul 6, 2016 at 7:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.