osm_conversion csv

This commit is contained in:
Tykayn 2022-08-03 11:26:43 +02:00 committed by tykayn
parent 2008f23920
commit 7bc952b614
2 changed files with 52 additions and 38 deletions

View File

@ -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;
@ -21,11 +21,14 @@ overpassDataJson['elements'].forEach((elem) => {
if (turn_ii >= turn_ii_limit) {
return
}
let line_properties = {
"ref": reference_prefix,
"ref": reference_prefix + turn_ii,
"way_id": elem.id,
"osm_link": "https://www.openstreetmap.org/way/" + elem.id,
"speedlimit": null,
"highway": null
"highway": null,
"name": null,
}
console.log("elem.id", elem.id)
if (elem.tags) {
@ -38,11 +41,12 @@ overpassDataJson['elements'].forEach((elem) => {
if (elem.tags.ref) {
// line_properties.ref += elem.tags.ref.replace(' ','-')
line_properties.ref += elem.tags.ref
line_properties.ref += '_' + elem.tags.ref.replace(' ', '-')
}
if (elem.tags.name) {
line_properties['name'] = elem.tags.name
}
if (elem.tags.maxspeed) {
console.log("elem.tags.maxspeed", elem.tags.maxspeed)
line_properties['speedlimit'] = elem.tags.maxspeed
}
}
@ -50,23 +54,30 @@ overpassDataJson['elements'].forEach((elem) => {
})
let lines_out = lines_csv.map(elem => {
let keys = Object.keys(elem)
let csv_line = '';
let ii = 0;
keys.forEach(keyName => {
csv_line += elem[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);
}

View File

@ -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,
1 ref,way_id,speedlimit,highway
2 94160_113859326https://www.openstreetmap.org/way/13859326,50,primary,Avenue de la Porte de Vincennes,
3 ,94160_217075650https://www.openstreetmap.org/way/17075650,30,secondary,Avenue Courteline,