Extract Data from ArcGIS JS API

03-17-2021 03:34 AM
New Contributor II


I need to let my users export data from an ArcGIS Online FeatureService as a shapefile. 

I am aware of solutions based on the shp-write JS library. However, the process of converting ArcGIS JSON to geojson and then exporting this is way too slow and buggy. The shp-write library do not have proper support for saving multiple polygons in one shapefile.


I have stumpled upon this: https://developers.arcgis.com/rest/analysis/api-reference/extract-data.htm

This seems to be exactly what I need. Is it possible to call this from the ArcGIS JS API? 


The REST API refers to an "analysis url", for example: http://<analysis url>/ExtractData/submitJob 

Is it possible to get such a thing for ArcGIS Online, or is it limited to on premise ArcGIS Server solutions?

0 Kudos
2 Replies
MVP Regular Contributor

Using the ArcGIS API for JavaScript, check out esriRequest(). Alternatively, it would be an ajax call; plain JS or jQuery for example. Could also try fetch().

0 Kudos
New Contributor II

Hi Blake,

The esriRequest makes it possible to request data, yes, but it is not clear where to request the data.

I have solved it by requesting geojson data directly from the Feature Service. Luckily, the layer is publicly available, so I don't need to worry about tokens. Using the terraformer/arcgis library to convert arcgis JSON to geojson is way too slow.

The geojson data CAN be converted with shp-write, however, you need to use the fixes done here, in order to export polygons: https://github.com/hwbllmnn/shp-write/tree/master/src 

It would be nice, if an export feature was available in the JS API right out of the box, but it obviously isn't. People expect to be able to work with shapefiles in ESRI products. :)

0 Kudos