Skip to content

Instantly share code, notes, and snippets.

@toutpt
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toutpt/4ae67703ceeecefaeac5 to your computer and use it in GitHub Desktop.
Save toutpt/4ae67703ceeecefaeac5 to your computer and use it in GitHub Desktop.
/*global _:false */
/**
* nom
* code
* type
* Site parent
* Service mainteneur
* long
* lat
*/
var _ = require('lodash');
var input = require('./highways.json');
var elements = input.elements;
var names = [];
var name;
var data = {};
_.forEach(elements, function (element) {
if (!element.tags){
return;
}
if (!element.tags.name) {
return;
}
name = element.tags.name;
if (!_.contains(names, name)) {
names.push(name);
data[element.id] = {
name: element.tags.name,
type: element.tags.highway
};
if (element.type === 'node') {
data[element.id].long = element.lon;
data[element.id].lat = element.lat;
}
if (element.type === 'way') {
var nodeid = element.nodes[0];
_.forEach(elements, function (node) {
if (node.type === 'node' && node.id === nodeid) {
data[element.id].long = node.lon;
data[element.id].lat = node.lat;
}
});
}
} else {
_.forOwn(data, function (value, key) {
if (value.name === name && element.type === 'node' && !value.lat) {
value.long = element.lon;
value.lat = element.lat;
}
});
}
});
var str;
_.forOwn(data, function (value, key) {
str = value.name + ';osm_highway_' + value.type + '_' + key + ';RTE;;';
if (value.lat) {
str += value.long + ';' + value.lat;
}
console.log(str);
});
/*
This has been generated by the overpass-turbo wizard.
The original search was:
“highway=* in vern-sur-seiche”
*/
[out:json][timeout:25];
// fetch area “vern-sur-seiche” to search in
{{geocodeArea:vern-sur-seiche}}->.searchArea;
// gather results
(
// query part for: “highway=*”
node["highway"]["name"](area.searchArea);
way["highway"]["name"](area.searchArea);
relation["highway"]["name"](area.searchArea);
);
// print results
out body;
>;
out skel qt;
{
"name": "osm",
"version": "1.0.0",
"description": "",
"main": "extract_sites.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"lodash": "^3.9.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment