-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_data.js
74 lines (67 loc) · 1.72 KB
/
get_data.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const ArgumentParser = require('argparse').ArgumentParser
const request = require('request')
const fs = require('fs')
const parser = new ArgumentParser({
addHelp: true,
description: 'Loads specified routes from OpenStreetMap Overpass API and saves them to a .osm file'
})
parser.addArgument(
[ '-f', '--file' ],
{
help: 'File to write data to (default: data.osm)',
defaultValue: 'data.osm'
}
)
parser.addArgument(
[ '-b', '--bbox' ],
{
help: 'Load all public transport routes which cross the specified bounding box (lat,lon,lat,lon)'
}
)
parser.addArgument(
[ 'id' ],
{
help: 'Load routes with the specified relation IDs',
nargs: '*'
}
)
parser.addArgument(
[ '-t', '--types' ],
{
help: 'When querying for a bbox, load routes of the specified types, e.g. "-t subway tram".',
defaultValue: [ 'train', 'subway', 'monorail', 'tram', 'trolleybus', 'bus', 'aerialway', 'ferry' ],
nargs: '*'
}
)
parser.addArgument(
[ '--format' ],
{
help: 'Format to load, either "XML" or "JSON". XML can be modified by OSM tools, e.g. JOSM.',
choices: [ 'XML', 'JSON' ],
defaultValue: 'XML'
}
)
let args = parser.parseArgs()
let query = '[out:' + args.format.toLowerCase() + '];('
if (args.bbox) {
query += 'relation[route~"^(' + args.types.join('|') + ')$"](' + args.bbox + ');'
}
if (args.id) {
query += args.id
.map(id => 'relation(' + id + ');')
.join('')
}
if (!args.id.length && !args.bbox) {
query += 'relation[route~"^(subway)$"](48.14,16.28,48.28,16.44);'
}
query += ');out meta;>;out meta;'
request(
{
method: 'POST',
url: 'https://overpass-api.de/api/interpreter',
body: query
},
(err, httpReq, body) => {
fs.writeFileSync(args.file, body)
}
)