Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm creating a web map using Leaflet, and I want to be able to grab feature layers from our ArcServer. I have successfully been able to retrieve a feature class as JSON, but Esri's JSON objects don't follow the GeoJSON standards so they cannot be displayed.

Does anyone know of a conversion script or tool that handles this? If not, I plan on creating a script to convert ArcServer JSON objects to GeoJSON.

share|improve this question
I was having trouble getting ogr2ogr to eat ESRI json coming from a MapServer feature query. (@SasaIvetic's example uses a FeatureServer request, and the MapServer result I need to consume must not have been interchangeable.) Anyway, this site totally did the trick: – elrobis Oct 12 '15 at 16:08
up vote 28 down vote accepted


ogr2ogr -f GeoJSON test.json "*&f=json" OGRGeoJSON

That command will read the query result directly from the URL. You can also supply it with a text file containing your JSON or you can directly supply encoded JSON on the command line. You can of course use ORG Python bindings to automate it within a script if necessary, or the library to do it in code.

For those that like web services, see Ogre an ogr2ogr web client which can convert json to geojson to and back, as well as geojson to shapefile.


share|improve this answer
I downloaded FWTools. When I run that command, I get the error 'Unable to open datasource 'My URL here' with the following drivers. -> ESRI Shapefile -> MapInfo File -> UK .NTF -> SDTS -> TIGER -> S57 -> DGN -> VRT -> REC -> Memory -> BNA -> CSV -> NAS -> GML -> GPX -> KML -> GeoJSON -> Interlis 1 -> Interlis 2 -> GMT -> SQLite -> ODBC -> PGeo -> OGDI -> PostgreSQL -> MySQL -> XPlane -> AVCBin -> AVCE00 -> DXF -> Geoconcept -> GeoRSS -> GPSTrackMaker -> VFK I don't see something like 'ESRI JSON' in the list of drivers. – Tanner Aug 3 '11 at 20:15
@Tanner: FWTools comes with OGR v1.7 where GeoJSON support was added with v1.8.0. I'm running GDAL/OGR 1.9dev here, though not through FWTools. I think I got them from – Sasa Ivetic Aug 3 '11 at 20:33
Thanks. I got this to work on the command line. I'm still working on getting it to work in my Javascript - any tips would be appreciated. – Tanner Aug 4 '11 at 18:03
@Tanner how did you get past that error? It's not a version issue for me but I'm getting the same error on my windows machine – kflaw Jun 22 at 19:45
@kflaw Sorry, but I don't recall exactly. I think I just used ogr2ogr on the command line, and didn't need or use FWTools. – Tanner Jun 23 at 17:19

You can also see Esri's geojson-utils on Github that "contains [javascript] utilities for converting GeoJSON to other geographic json formats and vice versa. Currently only GeoJSON to Esri JSON has been developed. Also, note that only geometries in the WGS84 coordinate system are supported."

share|improve this answer

ESRI JSON to GeoJSON (for OpenLayers) *Likely to be modified for Leaflet javascript

        //create esri JSON object
    var myReturn = "esriObj = "+xmlHttpGet(restCall, false);

I can now work with esriObj as a JSON object i.e. esriObj.geometryType. What happens in the xmlHttpGet method? Basically I create a XMLHttpRequest and pass in my REST URL – your can see this code here

3. OK i have my ‘ESRI query’ JSON object now I need to parse the features in this object and essentially create GeoJSON strings which the OpenLayers sample will be happy with – cue the code butchery…

function esriDeserialize(geojson)

    var element = document.getElementById('text');
    var type = document.getElementById("formatType").value;
    var features = formats['in'][type].read(geojson);
    var bounds;
        if(features.constructor != Array) {
            features = [features];
        for(var i=0; i<features.length;>
            if (!bounds) {
                bounds = features[i].geometry.getBounds();
            } else {

        var plural = (features.length &gt; 1) ? 's' : '';
        //element.value = features.length + ' feature' + plural + ' added'
    } else {
        element.value = 'Bad input ' + type;

function getEsriGeom(restCall){

    //call ESRI Rest API
    var element = document.getElementById('text');  

    //create esri JSON object
    var myReturn = "esriObj = "+xmlHttpGet(restCall, false);

    element.value = "";
    var coordPairsPerFeature = 0;

    //for each feature
    for (var i=0; i &lt; esriObj.features.length; i++)
        //get the geometry
        var o = esriObj.features[i].geometry;
        element.value = element.value + esriObj.features[i].attributes.ADMIN_NAME;

        //loop through all the rings
        for (var s=0; s &lt; o.rings.length; s++)
            //create geojson start &amp; end - i know i'm getting polygons
            var geojsonstart = '{"type":"Feature", "id":"OpenLayers.Feature.Vector_124", "properties":{}, "geometry":{"type":"Polygon", "coordinates":[['
            var geojsonend = ']]}, "crs":{"type":"OGC", "properties":{"urn":"urn:ogc:def:crs:OGC:1.3:CRS84"}}}';

            //the coordinates for this ring
            var coords = o.rings[s];

            //loop through each coordinate
            var coordPair="";
            for (var g=0; g &lt; coords.length; g++)
                coordPairsPerFeature = coordPairsPerFeature+1;

                    coordPair = coordPair+"["+coords[g]+"]";

            //combine to create geojson string

        element.value = element.value + "," + coordPairsPerFeature +"n";



share|improve this answer

Leaflet and ArGIS vector layer.

Working demo.

More on Leaflet and ArcGIS.

  • Leaflet and ArcGIS Server layers i.e. AgsDynamicLayer and AgsFeatureLayer.

You can get this fork which has support for ArcGIS server.

 var sitesLayer = new L.AgsDynamicLayer(
    { maxZoom: 19,
        attribution: "NOAA",
        opacity: 1,
        layers: 'show:2' });

ArcGIS Image Services and Leaflet

share|improve this answer

I've built a server object extension to generate GeoJSON from ArcGIS Server map services. It's been tested with 10.1 and 10.2 but not earlier.

share|improve this answer

Perhaps even easier you can use the Esri-leaflet library to add it natively as a layer in Leaflet.

share|improve this answer
Could you incorporate an example in your post outlining how this answer's the OP's question? – Paul Sep 26 '13 at 18:00

Its usually* pretty easy converting.

I made a script and there are others that work well too.

*The exception is multi-part polygons with holes which don't convert 1-to-1 without some geoprocessing.

share|improve this answer

For a one-time conversion I would have used the accepted answer from @Sasa Ivetic but needed something real-time, and Terraformer worked decently for that. Unfortunately it's only for single features by default, so for multiple features you need to loop through the array and add an ID to each feature:

var FeatureCollection = {
  type: "FeatureCollection",
  features: []

for (var i = 0; i < arcgis.features.length; i++) {
  var feature = Terraformer.ArcGIS.parse(arcgis.features[i]); = i;

This worked fine for me except on multi-part polygons (i.e. Alaska and its islands), but I'm new to this so it's possible I coded something incorrectly!

share|improve this answer

If its a one time query and you don't have more than 1000 features try pasting this into qgis by using the add vector layer - choose protocol and replace this arcgis rest URL with yours:*&f=json ... This assumes you have gdal 1.10 installed

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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