A NodeJS script to download all layers within a public or protected ArcGIS Online Feature or Map Service as GeoJSON.
npx agol-cache serviceURL [FORMAT] TOKEN
npx agol-cache serviceURL gpkg TOKEN
npx agol-cache serviceURL TOKEN
The npx
script will export all features to GeoJSON into an export
folder in the current directory and prefix all files with export_
. All other config options are set to their defaults. Additional format conversion options are available using gdal3.js
- see formats.json. If exporting to anything other than GeoJSON, the original GeoJSON file will be deleted after successful conversion. Converting extremely large geojson files has not been tested…the conversion may fail due to memory constraints since it uses the original geojson file as input.
Download all layers from an ArcGIS Online Feature Service or Map Service to GeoJSON. The tool will attempt to identify the Esri OID field or one can be provided. More details on the background and functionality can be found in the link below.
Exporting AGOL Feature Services
Using NodeJS and Batches to Transform an ArcGIS Online Feature Service to GeoJSON
const cache = require('agol-cache')
const url = 'https://services1.arcgis.com/fBc8EJBxQRMcHlei/ArcGIS/rest/services/NTF_Members_and_NR_Listings/FeatureServer/'
//can use async/aawit with layerByLayer: true
cache.featureServiceToGeoJSON(url, {
attachments: false, //whether or not to check the service for attachments
debug: false, //debugging is now on be default, which just means it writes to a log file, and the console logger is off if silent is set to false
esriIdField: "", //field to use for the esriIdField, used in the query parameters, if NULL it is determined by the service response
filter: "", //string to filter layer names
folder: './geojson-cache', //folder to write the log file and geojson cache, relative to working directory or absolute path
format: "json", //json or GeoJSON - json downloads the raw Esri JSON format then converts to GeoJSON (BETA), try this if using the GeoJSON endpoint fails
layerByLayer: true, //THIS OPTION HAS BEEN REMOVED AND IS ALWAYS TRUE
prefix: "test_", //prefix to add to the start of layer names
silent: true, //turn off viewing winston log messages and spinner "info" messages in the console
token: null //token to use for secured routes, taken from .env TOKEN variable,
pretty: false, //if true, the JSON output file will be formatted for human reading
timeout: 5000, //default is 5000, increase as needed
steps: 1000 //number of features queried on each request
outputFormat: "geojson" //for additional formats see lib/gdalVectorExtensions.js
parseDomains: false,
layers: true, //whether or not to download the layers as individual files - if false it skips all layers
tables: true //whether or not to download the tables as individual files - if false it skips all tables
}, (layers) => {
// console.log('output ' + layers.length + ' layers')
});
TOKEN=validtokenstring
layerByLayer
optiontables
option to download tables or skiplayers
option to download layers or skipgdal3.js
for converting the output geojson to additional vector formats [BETA]parseDomains
option to parse coded domains [BETA]pretty
option to format the output GeoJSON filetoken
option to add token in the config as well as the .env
fileparseDomains
default falsegdal3.js
.npx
functionality:field.domain.codedValues
field.getAllServices.js
that writes agol-services.json
and agol-services.csv
to the root folder containing all services for the given endpoint.
const { getAllServices } = require("./lib/getAllServices.js")
const config = {
debug: true,
silent: true,
timeout: 5000,
token: ''
};
getAllServices('https://sampleserver6.arcgisonline.com/arcgis/rest/services', config)
steps
option to limit the amount of features queried on each fetch request, which defaults to 1000. Lower this number if you get timeouts from the REST service.json
endpoint and convert the data to GeoJSON once downloadedconfig.timeout
option to set the fetch timeoutesriIdField
fetch
added back with additional fetch-retry
dependencyfetch
replaced with axios
and retry-axios
due to timeout errorsesriFieldTypeOID
field from the service definition
ogr2ogr -f MVT -dsco MINZOOM=10 -dsco MAXZOOM=14 target.mbtiles output/infile.geojson