First of all I am Japanese. I am posting this using a translation, so if there is anything wrong with the grammar, please feel free to ask me questions. I am looking to create a system that reads GPX files in Node.js and reads and displays the highest altitude, arrival and departure times, etc. from the GPX files.
app.get('/test_gpx' , (req, res) => {
const file = fs.createWriteStream("file.gpx");
http.get("filepath", response => {
response.pipe(file);
const fs = require("fs");
const stream = fs.createReadStream("./file.gpx", {
encoding: "utf8",
highWaterMark: 1024
});
let count = 0;
let total = 0;
let chunk;
global.variable_chunk;
stream.on("readable", () => {
while ( ( chunk = stream.read()) !== null ) {
count++;
total += chunk.length;
global.variable_chunk = global.variable_chunk + chunk;
}
});
stream.on("end", () => {
console.log(`The data was obtained in ${count} installments.`);
console.log(`Total ${total} bytes acquired.`);
var gpx = new gpxParser();
console.log(global.variable_chunk);
gpx.parse(global.variable_chunk);
var track = gpx;
console.log(track)
});
});
});
Lines 2 through 27 are the process of reading GPX files with fs and storing them in variables. npm uses GPX Parser.js. I don't know how to extract the information of the trkpt object because there is not much information in official tutorials etc. If anyone knows anything about this, I would appreciate it if you could enlighten me.