18

I am thinking about writing software to deal with GPS Tracks and Waypoints (mostly storing, displaying and calculating metrics such as speed, grade, and some simple statistics).

I wonder what should be the most conceptually robust data model regarding trackpoints, and here are some "candidates":

  1. Considering Tracks as sequences of Trackpoints:

    1.1. Tracks are considered "2D", since map projections are 2D. Trackpoints might or not have elevation, might or not have timestamp. Elevation and timestamp are consideres "extras", "optional". For terrestrial applications, elevation is a direct function of lat/lon (obtainable via DEM);

    1.2. Tracks are considered "3D" since geographic space is, indeed 3D, and the trajectory of the receiver is 3D (2D projection is thus a form of data reduction). Timestamp might or not be present (the track could have been drawn by hand).

    1.3. Tracks are considered "4D" (3 spatial + time). Thus, a hand-drawn map is a special case where elevation and timestamp are null or otherwise not present, but the Trackpoint properties are always "there".

  2. Tracks are considered dictionaries of streams, where all the streams have equal lengths. There is a list of latitudes, a list of longitudes, a list of elevations, one of timestamps, etc. This makes easy to calculate statistics of each property, and the concept of Trackpoint becomes "virtual" in a sense, since it is a cross-section of many streams.

If I understood right, GPX format adopts 1.1., KML adopts 1.2. (with no support for timestamp), and Strava API adopts 2. (in JSON format), but in the end these are just FILE formats for serialization and storage, not necessarily for modeling, computational representation and numbercrunching.

Is there any form that is preferrable, in an object-oriented sense, and why? (I believe that strong typing and sensible modelling at least would avoid operations that doesn't make sense).

EDIT: some "intriguing" additional questions:

  • Is a hand-drawn track CONCEPTUALLY the same thing that a device-recorded tracklog? Should they be of different data types?
  • Should it be considered "correct" that KML stores null elevations as zero? Zero IS an elevation, and if you don't know the elevation you shouldn't assign a numeric zero to it, isn't it?
  • Should it matter, in a track with elevation, if the elevation is extracted from DEM data ("offline") or from GPS data or barometric data ("in the field")? Should this be flagged in the Track object? Saved to different Trackpoint properties? Ignored? Should they be different collection datatypes?
  • If I edit a device-recorded track in a map editor (adding, moving and removing points), or combine tracks from different dates, how should the timestamps in the trackpoints be handled? Should they be "resetted" to null? Should an object (trackpoint collection) of a different type be created from the former ones?
Kirk Kuykendall
  • 25,787
  • 8
  • 65
  • 153
heltonbiker
  • 1,237
  • 1
  • 12
  • 30
  • 3
  • Tracks are a collection of points with x, y, z, m[] and time attributes. A CSV file containing these 5 values for each point captured is more than enough for a robust data model. If you need fancy things like <> and {} to help you organize your data - and meta data - you're doing it wrong.
  • – nagytech Jun 20 '13 at 04:59
  • 1
    I agree with just a good old CSV, it represents everything the GPS is recording. But, the GPX format is pretty common for GPS devices. This link may be worth something as both GPS and KML are XML data formats. http://stackoverflow.com/questions/1820129/when-and-why-is-xml-preferable-to-csv – Pete Jun 20 '13 at 05:27
  • While XML is 'great' and all (for the reasons in @Pete's linked post) none of those points are relevant. If anything, the overhead does nothing but slow down the number crunching, and bloat your data storage and transmission methods. Granted, if you're a mom-n-pop operation you'll never have enough data to encounter these issues, and your number crunching is not going to be intense. Either way, you won't have the resources to sustain operation this close the metal - so XML away. – nagytech Jun 20 '13 at 11:06
  • 1
    Note that this question has much more to do with MODELING and design of data (representation of its conceptual essence) than actual implementation. The comments so far focus in file formats, which is, from what I think, yet further away, because file formats depend more on the implementation medium than the nature of data itself. – heltonbiker Jun 20 '13 at 13:58
  • Expanding my comment above: how SHOULD a track be represented? Is, say, "elevation" an intrinsic property of a trackpoint, and thus must be present even if null? Or is it a "plus", that might be present or not. Is a hand-drawn track conceptually the same thing that a device-captured tracklog? (well, this last one would make a whole new question...) – heltonbiker Jun 20 '13 at 14:03
  • 1
    In OO terms, I've used a Line class that can hold the points (lat, lng, ele, time, speed, bearing, etc). And, from there Routes that represent hand drawn or intended "tracks" and Tracks that represent an actual track with time/speed data. Conceptually I DO think they are different (hand drawn and or supplied by a cartographer, or such, versus an actual track). The terms are just semantics, sure, but using real types has been helpful (rather than just mashing it all together as a "Track"). Also, when it comes to serialization formats, I'd consider GeoJSON: http://en.wikipedia.org/wiki/GeoJSON. – Charlie Collins Jun 20 '13 at 14:58
  • It seems to me that GeoJSON is very interesting (as JSON overall), but I wonder how this would fit in the notion of fancy <> and {} to organize the data, proposed by @Geoist... – heltonbiker Jun 20 '13 at 15:11
  • You should read something about "moving objects". There are several publications and also several implementations. You might start by reading: http://portal.acm.org/citation.cfm?doid=352958.352963 – jgrocha Nov 10 '13 at 23:01
  • @jgrocha You are right. I casually had the opportunity to read an excellent book, and one chapter in special is exactely about this: "Computational Movement Analysis, chapter 22 of the Springer Handbook of Geographic Information", which is available as ebook. – heltonbiker Nov 11 '13 at 13:52