Created
December 9, 2019 12:35
-
-
Save WesleyE/2300c7af21b45fdcd645a1c26a17fa16 to your computer and use it in GitHub Desktop.
Download ArcGis Features from Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
const https = require('https'); | |
var offset = 0; | |
var rowsPerFetch = 2000; | |
var totalRows = 459701; | |
var fetches = Math.ceil(totalRows / rowsPerFetch); | |
var offsetIterator = 0; | |
function getDownloadUrl(offset) { | |
return `https://services.arcgis.com/nSZVuSZjHpEZZbRo/ArcGIS/rest/services/Postcodevlakken_PC6/FeatureServer/0/query?where=1%3D1&objectIds=&time=&geometry=&geometryType=esriGeometryPolygon&inSR=&spatialRel=esriSpatialRelIntersects&resultType=none&distance=0.0&units=esriSRUnit_Meter&returnGeodetic=false&outFields=*&returnGeometry=true&returnCentroid=false&featureEncoding=esriDefault&multipatchOption=xyFootprint&maxAllowableOffset=&geometryPrecision=&outSR=4326&datumTransformation=&applyVCSProjection=false&returnIdsOnly=false&returnUniqueIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&returnQueryGeometry=false&returnDistinctValues=false&cacheHint=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&having=&resultOffset=${offset}&resultRecordCount=&returnZ=false&returnM=false&returnExceededLimitFeatures=true&quantizationParameters=&sqlFormat=none&f=pjson&token=` | |
} | |
function getData(url, offset) { | |
https.get(url, (resp) => { | |
let data = ''; | |
// A chunk of data has been recieved. | |
resp.on('data', (chunk) => { | |
data += chunk; | |
}); | |
// The whole response has been received | |
resp.on('end', () => { | |
fs.writeFileSync(`./data/pc6_${offset}.json`, data); | |
}); | |
}).on("error", (err) => { | |
console.log("Error: " + err.message); | |
}); | |
} | |
function loop() { | |
console.log(`${offsetIterator} of ${fetches}. Time left ${((fetches - offsetIterator)*3.5) / 60} minutes.`); | |
var url = getDownloadUrl(offset); | |
getData(url, offsetIterator); | |
offset = offset + rowsPerFetch; | |
offsetIterator++; | |
} | |
var intervalId = setInterval(() => { | |
if(offsetIterator < fetches) { | |
loop(); | |
} else { | |
clearInterval(intervalId); | |
} | |
}, 3400); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment