Saturday, 16 April 2016

qgis - Cannot load postgis layer from sql string in pyqgis


I'm trying to load a layer using the following code in qgis python console:


sql = "(select the_geom, ID from mytable)"
uri = QgsDataSourceURI()

uri.setConnection("localhost","5432","mydb","postgres","XXXX")
uri.setDataSource("myschema",sql,"the_geom","","ID")
vlayer = QgsVectorLayer(uri.uri(),"LayerName","postgres")
QgsMapLayerRegistry.instance().addMapLayer(vlayer)

It doesn't add the layer but also doesn't return any error.


I'm using QGIS 2.4.0-Chugiak




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...