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.5k29 gold badges115 silver badges350 bronze badges
asked Jul 6, 2016 at 6:24
1
  • 1
    did you try something like select * from table where ST_GeometryType(thegeomcolumn)='ST_Linestring'? Commented Jul 6, 2016 at 7:01

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.