Thursday, 2 June 2016

arcgis rest api - ESRI world imagery raster layer not working in Python Console


Have been using the usual code in python console to use the world imagery layer as a base map and have been pretty happy with this, from IEQGIS page


qgis.utils.iface.addRasterLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty+true","raster")

However, just stopped working...error msg below



It has been superseded by a plugin but can't find a way of getting this to work either. Any ideas why this does not work or which URL to put in the REST API?


Error message: Invalid Layer    GDAL provider: Cannot open GDAL dataset http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty+true: Invalid dataset dimensions : -2147483648 x -2147483648
Raster layer: Provider is not valid (provider: gdal, URI: http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty+true

Another more recent error:


GDAL provider: Cannot open GDAL dataset server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json: `server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json' does not exist in the file system, and is not recognised as a supported dataset name. 
Raster layer: Provider is not valid (provider: gdal, URI: server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json

Answer



Ironically my neighbour has come up with a fix - seems there is a bit of a bug. A way round this is as he describes:


"Here is how I managed to get the ArcGIS REST service to work:



gdal_translate --debug on http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer?f=json out.xml -of WMS


This produces the same error you see in QGIS: "ERROR 1: Invalid dataset dimensions : -2147483648 x -2147483648"


The error is being triggered because the layer is so large, there is a bug filed for this in the gdal_translate project. Even though it is erroring, gdal_translate does actually generate the required metadata that QGIS needs to add a Raster layer and allows you to tweak the tile level to a lower value to allow QGIS to display the layer. You need to use a working layer metadata file and, add this via the main menu: Layer -> Add Layer -> Add Raster Layer (Shift + CMD + R)"


So create an .xml file with: http://services.arcgisonline.com/arcgis/rest/services/World_Imagery/MapServer/tile/${z}/${y}/${x} -20037508.34278700 20037508.34278700 20037508.34278103 -20037508.34278103 22 1 top EPSG:3857 256 256


End point is an editable aerial raster layer - happy times


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