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'? Jul 6 '16 at 7:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.