I want to load the postgis layer to qgis canvas. I am using the following code but it is not loading the layer in canvas.
sql = "(SELECT * FROM table WHERE id = 20)"uri = QgsDataSourceURI()uri.setConnection("host", "5432", "databasename", "user", "password")uri.setDataSource("public","table", "the_geom", sql,"gid")print uri.uri()vlayer = QgsVectorLayer(uri.uri(), "test", "postgres")QgsMapLayerRegistry.instance().addMapLayer(vlayer)canvas.refresh()But the layer is not loaded.i dont know what i am doing wrong here?
أكثر...
sql = "(SELECT * FROM table WHERE id = 20)"uri = QgsDataSourceURI()uri.setConnection("host", "5432", "databasename", "user", "password")uri.setDataSource("public","table", "the_geom", sql,"gid")print uri.uri()vlayer = QgsVectorLayer(uri.uri(), "test", "postgres")QgsMapLayerRegistry.instance().addMapLayer(vlayer)canvas.refresh()But the layer is not loaded.i dont know what i am doing wrong here?
أكثر...