osm_conversion csv
This commit is contained in:
parent
2008f23920
commit
7bc952b614
|
@ -7,7 +7,7 @@ let header_csv = ["ref", "way_id", "speedlimit", "highway"]
|
||||||
let lines_csv = []
|
let lines_csv = []
|
||||||
const sourceFilePath = "./overpass_results/export_saint_mande.json"
|
const sourceFilePath = "./overpass_results/export_saint_mande.json"
|
||||||
const overpassDataJson = require(sourceFilePath)
|
const overpassDataJson = require(sourceFilePath)
|
||||||
const reference_prefix = "75_";
|
let reference_prefix = "94160_";
|
||||||
|
|
||||||
let turn_ii = 0;
|
let turn_ii = 0;
|
||||||
let turn_ii_limit = 3;
|
let turn_ii_limit = 3;
|
||||||
|
@ -16,57 +16,68 @@ console.log("overpassDataJson elements", overpassDataJson['elements'].length)
|
||||||
|
|
||||||
overpassDataJson['elements'].forEach((elem) => {
|
overpassDataJson['elements'].forEach((elem) => {
|
||||||
|
|
||||||
// limit turns for dev time
|
// limit turns for dev time
|
||||||
turn_ii++
|
turn_ii++
|
||||||
if (turn_ii >= turn_ii_limit) {
|
if (turn_ii >= turn_ii_limit) {
|
||||||
return
|
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,
|
if (elem.tags.ref) {
|
||||||
"way_id": elem.id,
|
|
||||||
"speedlimit": null,
|
line_properties.ref += '_' + elem.tags.ref.replace(' ', '-')
|
||||||
"highway": null
|
|
||||||
}
|
}
|
||||||
console.log("elem.id", elem.id)
|
if (elem.tags.name) {
|
||||||
if (elem.tags) {
|
line_properties['name'] = elem.tags.name
|
||||||
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
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 keys = Object.keys(elem)
|
||||||
let csv_line = '';
|
let csv_line = '';
|
||||||
keys.forEach(keyName=>{
|
let ii = 0;
|
||||||
csv_line += elem[keyName]+', '
|
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"
|
return csv_line + "\n"
|
||||||
});
|
});
|
||||||
console.log("lines_out", lines_out)
|
writeCSVOutput();
|
||||||
// writeCSVOutput();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function writeCSVOutput() {
|
function writeCSVOutput() {
|
||||||
|
|
||||||
|
|
||||||
|
let content = header_csv.join(',') + '\n' + lines_out;
|
||||||
fs.writeFile('output/' + exportFileName, header_csv.join(',') + '\n' + lines_out, function (err, data) {
|
console.log("content", content)
|
||||||
|
fs.writeFile('output/' + exportFileName, content, function (err, data) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
|
Loading…
Reference in New Issue