[GIS] Accessing GeoJSON from ArcGIS online rest API

arcgis-javascript-apigeojson

I have some features published on ArcGIS online. I'm accessing it as a feature service. I need to use that feature service as a GeoJSON and display it on the map. Is there any sandbox example on how to display GeoJSON on to the map or can any one share an example code on it using ArcGIS javascript API?

Best Answer

You submit a query to the ArcGIS REST API interface of your ArcGIS Online organization. There is one AGOL organization that is publicly available that is used by Esri for demos.

http://services1.arcgis.com/hLJbHVT9ZrDIzK0I/ArcGIS/rest/services

Here is a feature service with a layer:

http://services1.arcgis.com/hLJbHVT9ZrDIzK0I/ArcGIS/rest/services/EQMagGt4/FeatureServer/0

It is just about submitting a query. In here, I select all earthquake points with a magnitude larger than 5.5:

http://services1.arcgis.com/hLJbHVT9ZrDIzK0I/arcgis/rest/services/EQMagGt4/FeatureServer/0/query?where=MAG+%3E+5.5&objectIds=&time=&geometry=&geometryType=esriGeometryEnvelope&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=&units=esriSRUnit_Meter&outFields=*&returnGeometry=true&multipatchOption=&maxAllowableOffset=&geometryPrecision=&outSR=4326&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnDistinctValues=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&resultOffset=&resultRecordCount=&returnZ=false&returnM=false&quantizationParameters=&sqlFormat=none&f=pgeojson&token=

Remember to set up the proper output spatial reference as well as to choose GeoJSON for your output data format.

Here is a GeoJSON saved as a gist on GitHub.

Your two friends are geojsonlint for validating GeoJSON and geojsonio for interactive review of the GeoJSON and map plotting.

There are cool tools built by Esri, available on GitHub for plotting GeoJSON with JS API.