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)
select * from table where ST_GeometryType(thegeomcolumn)='ST_Linestring'
?