-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
35 lines (30 loc) · 924 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const fs = require('fs')
const co = require('co')
const overpass = require('./overpass')
const wikimapia = require('./wikimapia')
const createGeoJSON = input => co(function* () {
const overpassFeatures = input.filter(item => (
item.type === 'overpass-query'
)).map(overpass)
const wikimapiaFeatures = input.filter(item => (
item.type === 'wikimapia-id'
)).map(item => wikimapia(item.id))
const features = yield [...overpassFeatures, ...wikimapiaFeatures]
return {
type: 'FeatureCollection',
features,
}
})
const writeOutput = output => new Promise((resolve, reject) => {
fs.writeFile('output.geojson', JSON.stringify(output, null, 2), err => {
if (err) reject(err)
resolve()
})
})
const start = filename => {
const input = JSON.parse(fs.readFileSync(filename, {encoding: 'utf-8'}))
createGeoJSON(input)
.then(writeOutput)
.catch(console.error)
}
start(process.argv[2])