I'm trying to add an ArcGIS MapServer layer from python code. The code I am running (currently via the console to test) is:

data = QgsDataSourceURI()
data.setParam("url", "http://egis.fire.ca.gov/arcgis/rest/services/FRAP/DE_HHZTier2/MapServer")
data.setParam("layer", "0")

iface.addRasterLayer(str(data.encodedUri()), "mylayer", "arcgismapserver")

This results in the error:

Invalid Layer: AMSProvider Could not parse spatial reference Raster layer Provider is not valid (provider: arcgismapserver, URI: layer=0&url=http://egis.fire.ca.gov/arcgis/rest/services/FRAP/DE_HHZTier2/MapServer

Adding the same service/layer via the UI (Layer -> Add Layer -> Add ArcGIS MapServer Layer) works great.


Sorted it out, the data source uri needs to be space delimited. So changing it to:

iface.addRasterLayer("url='http://.../MapServer' layer='0'", "mylayer", "arcgismapserver") 

Does the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.