Created
January 31, 2019 14:13
-
-
Save ZhangYiJiang/cc29b971da8ed36fa073a528fa5e8dec to your computer and use it in GitHub Desktop.
Get all places of interest in NUS
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
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