Skip to content

Instantly share code, notes, and snippets.

@ejain
Created January 2, 2020 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejain/14f36c114144b8001e5bfd725ee8681d to your computer and use it in GitHub Desktop.
Save ejain/14f36c114144b8001e5bfd725ee8681d to your computer and use it in GitHub Desktop.
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