From 7bc952b61436067934a91c49f5efe73272f6e407 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 3 Aug 2022 11:26:43 +0200 Subject: [PATCH] osm_conversion csv --- osm_conversion/app.js | 87 +++++++++++-------- ...-saint-mande_date-made-2022-08-03_full.csv | 3 + 2 files changed, 52 insertions(+), 38 deletions(-) create mode 100644 osm_conversion/output/bdd-vitesses-fr-osm_ways_zone-saint-mande_date-made-2022-08-03_full.csv diff --git a/osm_conversion/app.js b/osm_conversion/app.js index a965bf66..010a574e 100644 --- a/osm_conversion/app.js +++ b/osm_conversion/app.js @@ -7,7 +7,7 @@ let header_csv = ["ref", "way_id", "speedlimit", "highway"] let lines_csv = [] const sourceFilePath = "./overpass_results/export_saint_mande.json" const overpassDataJson = require(sourceFilePath) -const reference_prefix = "75_"; +let reference_prefix = "94160_"; let turn_ii = 0; let turn_ii_limit = 3; @@ -16,57 +16,68 @@ console.log("overpassDataJson elements", overpassDataJson['elements'].length) overpassDataJson['elements'].forEach((elem) => { - // limit turns for dev time - turn_ii++ - if (turn_ii >= turn_ii_limit) { - return + // 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 } - let line_properties = { - "ref": reference_prefix, - "way_id": elem.id, - "speedlimit": null, - "highway": null + + if (elem.tags.ref) { + + line_properties.ref += '_' + elem.tags.ref.replace(' ', '-') } - 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 - } - - if (elem.tags.ref) { - - // line_properties.ref += elem.tags.ref.replace(' ','-') - line_properties.ref += elem.tags.ref - } - if (elem.tags.maxspeed) { - console.log("elem.tags.maxspeed", elem.tags.maxspeed) - line_properties['speedlimit'] = elem.tags.maxspeed - } + if (elem.tags.name) { + line_properties['name'] = elem.tags.name } - lines_csv.push(line_properties) - }) + if (elem.tags.maxspeed) { + line_properties['speedlimit'] = elem.tags.maxspeed + } + } + lines_csv.push(line_properties) +}) + +let lines_out = lines_csv.map(elem => { -let lines_out = lines_csv.map(elem => { let keys = Object.keys(elem) let csv_line = ''; - keys.forEach(keyName=>{ - csv_line += elem[keyName]+', ' + let ii = 0; + keys.forEach(keyName => { + csv_line += elem[keyName] + if(ii < 1? '': ', '){ + csv_line += ',' + } + ii++ + console.log("ii, elem[keyName]", ii, elem[keyName]) + }) return csv_line + "\n" }); -console.log("lines_out", lines_out) -// writeCSVOutput(); - +writeCSVOutput(); function writeCSVOutput() { - - fs.writeFile('output/' + exportFileName, header_csv.join(',') + '\n' + lines_out, function (err, data) { + let content = header_csv.join(',') + '\n' + lines_out; + console.log("content", content) + fs.writeFile('output/' + exportFileName, content, function (err, data) { if (err) { return console.log(err); } diff --git a/osm_conversion/output/bdd-vitesses-fr-osm_ways_zone-saint-mande_date-made-2022-08-03_full.csv b/osm_conversion/output/bdd-vitesses-fr-osm_ways_zone-saint-mande_date-made-2022-08-03_full.csv new file mode 100644 index 00000000..cb09dc5e --- /dev/null +++ b/osm_conversion/output/bdd-vitesses-fr-osm_ways_zone-saint-mande_date-made-2022-08-03_full.csv @@ -0,0 +1,3 @@ +ref,way_id,speedlimit,highway +94160_113859326https://www.openstreetmap.org/way/13859326,50,primary,Avenue de la Porte de Vincennes, +,94160_217075650https://www.openstreetmap.org/way/17075650,30,secondary,Avenue Courteline,