2022-08-03 11:10:08 +02:00
|
|
|
/**
|
|
|
|
* converter of overpass results to CSV
|
|
|
|
*/
|
2022-08-03 12:18:19 +02:00
|
|
|
const zone_name="paris-13e-arr";
|
|
|
|
const code_postal = "75013";
|
2022-08-03 11:10:08 +02:00
|
|
|
|
2022-08-03 12:18:19 +02:00
|
|
|
const exportFileName = `bdd-vitesses-fr-osm_ways_zone-${zone_name}_date-made-2022-08-03_full.csv`
|
2022-08-03 11:54:32 +02:00
|
|
|
let header_csv = ["national_ref", "way_id", "osm_link", "name", "highway_tag","speed_limit"]
|
2022-08-03 11:10:08 +02:00
|
|
|
let lines_csv = []
|
2022-08-03 12:18:19 +02:00
|
|
|
const sourceFilePath = `./overpass_results/${code_postal}.json`
|
2022-08-03 11:10:08 +02:00
|
|
|
const overpassDataJson = require(sourceFilePath)
|
2022-08-03 12:18:19 +02:00
|
|
|
const reference_prefix = `V${code_postal}_`;
|
2022-08-03 11:54:32 +02:00
|
|
|
|
|
|
|
let counter_no_speedlimit = 0;
|
|
|
|
let counter_highways = overpassDataJson['elements'].length;
|
2022-08-03 11:10:08 +02:00
|
|
|
|
|
|
|
let turn_ii = 0;
|
2022-08-03 11:54:32 +02:00
|
|
|
let turn_ii_limit = 2000;
|
2022-08-03 11:10:08 +02:00
|
|
|
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 = {
|
2022-08-03 11:54:32 +02:00
|
|
|
"ref": ""+reference_prefix + turn_ii,
|
2022-08-03 11:26:43 +02:00
|
|
|
"way_id": elem.id,
|
2022-08-03 11:54:32 +02:00
|
|
|
"osm_link": `"https://www.openstreetmap.org/way/${elem.id}"`,
|
2022-08-03 11:26:43 +02:00
|
|
|
"name": null,
|
2022-08-03 11:54:32 +02:00
|
|
|
"highway": null,
|
|
|
|
"speedlimit": null,
|
2022-08-03 11:26:43 +02:00
|
|
|
}
|
|
|
|
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
|
2022-08-03 11:54:32 +02:00
|
|
|
}else{
|
|
|
|
counter_no_speedlimit++
|
2022-08-03 11:26:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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:54:32 +02:00
|
|
|
keys.forEach(keyName => {
|
2022-08-03 11:26:43 +02:00
|
|
|
csv_line += elem[keyName]
|
2022-08-03 11:30:28 +02:00
|
|
|
csv_line += ';'
|
2022-08-03 11:26:43 +02:00
|
|
|
|
2022-08-03 11:10:08 +02:00
|
|
|
})
|
|
|
|
return csv_line + "\n"
|
|
|
|
});
|
2022-08-03 11:54:32 +02:00
|
|
|
|
|
|
|
|
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:54:32 +02:00
|
|
|
// console.log("content", content.replace(','+reference_prefix, reference_prefix))
|
2022-08-03 11:26:43 +02:00
|
|
|
fs.writeFile('output/' + exportFileName, content, function (err, data) {
|
2022-08-03 11:10:08 +02:00
|
|
|
if (err) {
|
|
|
|
return console.log(err);
|
|
|
|
}
|
2022-08-03 12:18:19 +02:00
|
|
|
console.log("highways without speedlimit", counter_no_speedlimit)
|
2022-08-03 11:54:32 +02:00
|
|
|
console.log("on", counter_highways)
|
2022-08-03 12:18:19 +02:00
|
|
|
console.log("missing speedlimit data : ", Math.floor( counter_no_speedlimit * 100 /counter_highways ) + "%" )
|
2022-08-03 11:54:32 +02:00
|
|
|
console.log(" ")
|
2022-08-03 11:10:08 +02:00
|
|
|
console.log('wrote output file', exportFileName);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|