Last active
January 21, 2016 10:20
-
-
Save zdila/856ca7a53495b16e4271 to your computer and use it in GitHub Desktop.
overpass_turbo_trails_to_gpx
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
// export NODE_PATH=/usr/local/lib/node_modules | |
// https://overpass-turbo.eu/ | |
// [out:json]; | |
// relation(area:3600014296)[route=bicycle]({{bbox}}); | |
// out body; | |
// >; | |
// out skel qt; | |
var fs = require('fs'); | |
var obj = JSON.parse(fs.readFileSync('export.json', 'utf8')); | |
var nodes = {}; | |
obj.elements.filter(e => e.type === 'node').forEach(e => { | |
// id, lat, lon | |
nodes[e.id] = {lat: e.lat, lon: e.lon}; | |
}); | |
var ways = {}; | |
obj.elements.filter(e => e.type === 'way').forEach(e => { | |
// id, nodes | |
ways[e.id] = e.nodes; | |
}); | |
function s(s) { | |
return s ? (s + "").replace("/", ",") : ""; | |
} | |
obj.elements.filter(e => e.type === 'relation' && e.tags.state !== 'proposed').forEach(e => { | |
var builder = require('xmlbuilder'); | |
var gpx = builder.create("gpx") | |
.att('xlns', 'http://www.topografix.com/GPX/1/1') | |
.att('version', '1.1') | |
.att('xmlns:xsi', 'http://www.w3.org/2001/XMLSchema-instance') | |
.att('xsi:schemaLocation', 'http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd'); | |
var trk = gpx.ele('trk'); | |
e.members.filter(m => m.type === 'way').forEach(m => { | |
trkseg = trk.ele('trkseg'); | |
ways[m.ref].forEach(n => { | |
var node = nodes[n]; | |
trkseg.ele('trkpt', {lat: node.lat, lon: node.lon}); | |
}); | |
}); | |
fs.writeFileSync("ct/" + (e.id + " | " + s(e.tags.colour) + " | " + s(e.tags.ref) + " | " + s(e.tags.name)).replace(" ", " ") + ".gpx", gpx.end({pretty: true})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment