Created
January 2, 2020 20:17
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"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