Skip to content

Instantly share code, notes, and snippets.

@ZhangYiJiang
Created January 31, 2019 14:13
Show Gist options
  • Save ZhangYiJiang/cc29b971da8ed36fa073a528fa5e8dec to your computer and use it in GitHub Desktop.
Save ZhangYiJiang/cc29b971da8ed36fa073a528fa5e8dec to your computer and use it in GitHub Desktop.
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