Thursday 15 March 2012

pyqt4 - How to load a raster layer using PyQGIS? -



pyqt4 - How to load a raster layer using PyQGIS? -

although there posts on matter, there no reply in of them. why asking again.

one post found http://gis.stackexchange.com/questions/68032/raster-layer-invalid

i read info next link: https://hub.qgis.org/wiki/17/arcgis_rest .

i used command: gdal_translate "http://server.arcgisonline.com/arcgis/rest/services/world_imagery/mapserver?f=json&pretty=true" s.xml -of wms. , generated file successfully. however, when seek open file , assuming provider wms, code study layer invalid.

the code used is:

file = qfiledialog.getopenfilename(self, "open wms", ".", "wms (*.xml)") fileinfo = qfileinfo(file) # add together layer layer = qgsrasterlayer(file, fileinfo.filename(),"wms") if not layer.isvalid(): print "failed load." homecoming

i take file dialog box.

i tried other command: qgis.utils.iface.addrasterlayer("http://server.arcgisonline.com/arcgis/rest/services/world_imagery/mapserver?f=json&pretty=true","raster") using next code:

layer = qgsrasterlayer("http://server.arcgisonline.com/arcgis/rest/services/world_imagery/mapserver?f=json&pretty=true", "layer") if not layer.isvalid(): print "failed load." homecoming

it study "failed load". original command can run in qgis python command line. also, if seek come in code in python console, layer.isvalid() homecoming true. not working in standalone script.

answer can found here: http://gis.stackexchange.com/questions/120823/how-to-load-a-wms-layer-using-pyqgis.

basically, version problem. if have qgis previous v2.6, not work. fixed 2.6

if still not working you, have problem environment variable settings.

pyqt4 qgis

No comments:

Post a Comment