Connecting to ArcGIS "mapserver" layers

Although Arcgis servers can be configured to provide WMS and WFS services, they are often only configured to provide REST and SOAP services.

Raster arcgis "mapserver" layers

It is possible to connect to these layers in QGIS via the REST interface.
Firstly (and the most difficult part) you need to find the URL for the REST service for your layer. E.g. you might want to use a layer that is available in the ESRI "Maps for Personal Use" web map at: http://www.arcgis.com/home/webmap/viewer.html?useExisting=1
Hopefully with a little googling you will be able to find the address where you can browse the "ArcGIS services directory" of your favourite ArcGIS server. In this case it is: http://server.arcgisonline.com/ArcGIS/rest/services/

Find the layer that you want, copy the url for the REST service, and now you have at least two options:
1. In the QGIS Python console, run this:
qgis.utils.iface.addRasterLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true","raster")
2. Create a gdal service description file, e.g. by running this in a terminal:
gdal_translate "http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer?f=json&pretty=true" s.xml -of WMS
You can now load this file into QGIS, e.g. by drag-and-drop.

Vector arcgis "mapserver" layers, "globeserver" layers and "featureserver" layers

It is not possible to establish a direct connection to an ArcGIS Server in QGIS for vectors layers. HOWEVER you can use the ogr2ogr utility provided in GDAL/OGR (v1.9 and up - http://www.gdal.org/) to translate the E$RI formatted JSON response to a query you can send to the server. The ArcGIS Server must implement E$RI's Geoservices REST v1.0 (http://www.esri.com/industries/landing-pages/geoservices/geoservices), however the vast majority will, as this interface is used by a number of E$RI's web mapping APIs.

Here is the process, which should work for both /MapServer/ and /FeatureServer/ alike:

Step 1
Find the ArcGIS "REST Services Directory" - 95% of the time this will look [www.website.domain]/ArcGIS/rest/services
  • TIP- try this using your favorite search engine: [search terms] +"/ArcGIS/rest/services" or if you know of a webmap that uses an ArcGIS Server, open the 'developer tool' in your web browser and review the html or 'network traffic' to find the url that the webmap is calling to for its data.

Here is an example: http://geodata.epa.gov/arcgis/rest/services/

Step 2
Navigate to the MapServer or FeatureServer your interested in (Service Directory -> Folder ->/ MapServer ->/ Layer). Note that you'll have to submit a separate command/query for each layer/objectid # on the MapServer...

Here is an example: http://geodata.epa.gov/arcgis/rest/services/OAR/USEPA_NEI_2005/MapServer/1/

Step 3
Add the following to the end of your URL:

query?where=objectid+%3D+objectid&outfields=*&f=json

So it should end up looking something like this:

http://geodata.epa.gov/arcgis/rest/services/OAR/USEPA_NEI_2005/MapServer/1/query?where=objectid+%3D+objectid&outfields=*&f=json

Step 4
Now open GDAL/OGR command line (NOTE- you may want to first copy and paste the GDAL folder or "ogr2org.exe" to a new folder where you'll want the data to save to). Windows users can use the OSGeo4w installer going to advance install and select all the GDAL commandlines and libraries to install into this new folder (make sure you're installing GDAL v1.9 or higher), linux users I won't have to tell you what to do, because your smart enough, Mac/OSX users as always your on your own :).

Copy and Paste the following into your favorite text editer, making sure you rename the filename (NOTE:No spaces in the filename) and URL:

ogr2ogr -f GeoJSON [FILENAME].json "[URL]" OGRGeoJSON –gt 1000

Review other operations for the command here: http://www.gdal.org/ogr2ogr.html

Should look something like this:

ogr2ogr -f GeoJSON OAR_USEPA_NEI_2005_(1).json "http://geodata.epa.gov/arcgis/rest/services/OAR/USEPA_NEI_2005/MapServer/1/query?where=objectid+%3D+objectid&outfields=*&f=json" OGRGeoJSON –gt 1000

Now all you need to change for each layer is the # for the objectid (in the case /1/) and the FILENAME.

  • This has worked for lines, polygons, points. I DID NOT test it on multi-geometry datasets that are sometimes used in ArcGIS Server layers
  • The commandline may give you an error that the CRS/Projection wasn't recognized, ignore this for the moment as long as the new file was created.

Step 5
Open the newly created file as a GeoJSON vector or drag and drop this file into QGIS. The features may not appear at first, if you received the error that I mentioned above, you'll have to first manually set the CRS to the projection the server used, you should be able to find this as "Spatial Reference:" on the MapServer page in the ArcGIS Services Directory.

If someone is interested in developing a script/plugin for QGIS, please let me know