mapbox/togeojson — pull request #58 by sedenardi (2014-12-10 21:27:02+00:00)
Title: Preserve coordinate times for both GPX and KML files (if present)

Both GPX (http://www.topografix.com/GPX/1/1/) and KML (https://developers.google.com/kml/documentation/kmlreference#when) specs allow for storing a time stamp that corresponds to a coordinate. While the GeoJSON spec (http://geojson.org/geojson-spec.html) doesn't explicitly define this, I find it useful to preserve this information when converting the GPX and KML formats.

I've added this data as an array of strings called "times" that's a field of the "geometry" object, so "times" will be a sibling of "coordinates". For example, the KML code

...

2014-06-23T20:29:08Z
2014-06-23T20:29:11Z
2014-06-23T20:29:17Z
2014-06-23T20:29:23Z
-73.972843 40.765081 68
-73.97285100000001 40.765099 64.40000000000001
-73.972765 40.765181 61.79999999999999
-73.972731 40.765263 59.70000000000001

...

and GPX code

...

68.02014-06-23T20:29:08Z
64.42014-06-23T20:29:11Z
61.82014-06-23T20:29:17Z
59.72014-06-23T20:29:23Z

...

will convert to this GeoJSON code

...
"geometry": {
"type": "LineString",
"coordinates": [
[
-73.972843,
40.765081,
68
],
[
-73.972851,
40.765099,
64.4
],
[
-73.972765,
40.765181,
61.8
],
[
-73.972731,
40.765263,
59.7
]
],
"times": [
"2014-06-23T20:29:08Z",
"2014-06-23T20:29:11Z",
"2014-06-23T20:29:17Z",
"2014-06-23T20:29:23Z"
]
}
...

If the source GPX and KML files don't contain any time data then the resulting GeoJSON object will not contain the new "times" field.

Let me know if you have any questions, comments, or concerns.