scripts/osm_conversion/app.js

86 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-08-03 11:10:08 +02:00
/**
* converter of overpass results to CSV
*/
const exportFileName = "bdd-vitesses-fr-osm_ways_zone-saint-mande_date-made-2022-08-03_full.csv"
let header_csv = ["ref", "way_id", "speedlimit", "highway"]
let lines_csv = []
const sourceFilePath = "./overpass_results/export_saint_mande.json"
const overpassDataJson = require(sourceFilePath)
2022-08-03 11:26:43 +02:00
let reference_prefix = "94160_";
2022-08-03 11:10:08 +02:00
let turn_ii = 0;
let turn_ii_limit = 3;
const fs = require('fs')
console.log("overpassDataJson elements", overpassDataJson['elements'].length)
overpassDataJson['elements'].forEach((elem) => {
2022-08-03 11:26:43 +02:00
// limit turns for dev time
turn_ii++
if (turn_ii >= turn_ii_limit) {
return
}
let line_properties = {
"ref": reference_prefix + turn_ii,
"way_id": elem.id,
"osm_link": "https://www.openstreetmap.org/way/" + elem.id,
"speedlimit": null,
"highway": null,
"name": null,
}
console.log("elem.id", elem.id)
if (elem.tags) {
console.log("elem.tags.highway", elem.tags.highway)
if (elem.tags.highway) {
line_properties.highway = elem.tags.highway
2022-08-03 11:10:08 +02:00
}
2022-08-03 11:26:43 +02:00
if (elem.tags.ref) {
2022-08-03 11:10:08 +02:00
2022-08-03 11:26:43 +02:00
line_properties.ref += '_' + elem.tags.ref.replace(' ', '-')
2022-08-03 11:10:08 +02:00
}
2022-08-03 11:26:43 +02:00
if (elem.tags.name) {
line_properties['name'] = elem.tags.name
}
if (elem.tags.maxspeed) {
line_properties['speedlimit'] = elem.tags.maxspeed
}
}
lines_csv.push(line_properties)
})
2022-08-03 11:30:28 +02:00
let lines_out = lines_csv.map(elem => {
2022-08-03 11:10:08 +02:00
let keys = Object.keys(elem)
let csv_line = '';
2022-08-03 11:26:43 +02:00
keys.forEach(keyName => {
csv_line += elem[keyName]
2022-08-03 11:30:28 +02:00
csv_line += ';'
2022-08-03 11:26:43 +02:00
console.log("ii, elem[keyName]", ii, elem[keyName])
2022-08-03 11:10:08 +02:00
})
return csv_line + "\n"
});
2022-08-03 11:26:43 +02:00
writeCSVOutput();
2022-08-03 11:10:08 +02:00
function writeCSVOutput() {
2022-08-03 11:30:28 +02:00
let content = header_csv.join(';') + ';\n' + lines_out;
console.log(" ")
2022-08-03 11:26:43 +02:00
console.log("content", content)
fs.writeFile('output/' + exportFileName, content, function (err, data) {
2022-08-03 11:10:08 +02:00
if (err) {
return console.log(err);
}
console.log('wrote output file', exportFileName);
});
}