Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Build a GPX file from a CSV file exported from dashboard.automatic.com.
"use strict";
var csv = require("ya-csv");
var polyline = require("polyline");
var moment = require("moment-timezone");
var togpx = require("togpx")
var reader = csv.createCsvStreamReader(process.stdin, { columnsFromHeader : true });
var geojson = {
"type": "FeatureCollection",
"features": []
};
reader.addListener("data", function(row) {
var points = polyline.decode(row["Path"]).map(point => [ point[1], point[0] ]);
var begin = moment.tz(row["Start Time"], "YYYY-MM-DD h:mm A", "America/Los_Angeles").utc().format("YYYY-MM-DDTHH:mm:ss.SSSSZ");
var times = Array(points.length).fill(begin);
geojson.features.unshift({
"type": "Feature",
"geometry": {
"type": "LineString",
"coordinates": points
},
"properties": {
"times": times
}
});
});
reader.addListener("end", function(row) {
//console.log(JSON.stringify(geojson, null, " "));
console.log(togpx(geojson));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment