Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get all places of interest in NUS
import axios from 'axios'
import * as fs from 'fs-extra'
import * as _ from 'lodash'
const POI_NETWORK_URL = 'https://arcgis.ami-lab.org/arcgis/rest/services/FULL_NUS_NETWORK_051017/FULL_NUS_NETWORK_150118/MapServer/8/query'
async function getPoi() {
let lastId = 0;
let features;
const allPlaces = [];
// Repeatedly query the POI endpoint for features until it runs out
do {
const where = `OBJECTID > ${lastId}`;
const res = await axios.get(POI_NETWORK_URL, {
params: {
where,
// Return all fields
outFields: '*',
// Return x and y
returnGeometry: true,
// Return z (altitude - unreliable)
returnZ: true,
returnM: true,
f: 'json'
}
});
features = res.data.features;
allPlaces.push(...features);
const lastFeature = _.last(features);
if (lastFeature) {
lastId = lastFeature.attributes.OBJECTID;
} else {
break;
}
console.log(`Queried ${features.length} POI with lastId = ${lastId}`);
} while (features.length > 0);
fs.outputJSON('poi.json', allPlaces, { spaces: 2 })
}
getPoi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.