8

I need to store a series of GPS points with timestamps in the database (traces of various vehicles).

I am wondering which of two approaches to choose for storing them in the PostGIS table: 1.) Each point in own row with separate column for timestamp and one for track ID

2.) Use Linestring or MultiLineString with fourth M coordinate which would contain UNIX timestamp of the time for the point on the track. This would mean single row for each separate track.

1
  • I don't understand what you mean by a fourth M coordinate which would contain UNIX timestamp. Can you be more specific? Is it not better to store the timestamp in a separate field? Commented Jul 20, 2016 at 15:56

3 Answers 3

4

Personally I store data collected by my GPS unit as a point layer with a time stamp field, then I can use ST_Makeline if I need the line strings. If you have Postgres 9.0+ you can use an ORDER BY in your aggregate calls to make sure the line goes from point to point in chronological order. I lose the M values along the created lines, but if I need them I always have the point layer I can throw on in the background.

2

It depends on what you will want to do with the data once they are loaded in the database. If each data point has associated attributes in addition to time (e.g., engine temperature reading, a photo) or of you will want to use the point data in an analysis, then storing each datum in its own row is a good choice.

If each track has associated attributes (e.g., event name) or your analyses will be on tracks (e.g., find track crossings), then it makes more sense to store each as a (MULTI)LINESTRING.

If you choose one approach it won't prevent you from doing the analyses in the other. It will just require some extra steps.

0

I used for timestamp value of coordinate 'z' part of point x-y-z, trimmed to seconds (not milliseconds) minus start of first coordinate to avoid store of big 'z' value.

1
  • What about using Z for elevation?
    – Greg
    Commented Aug 14, 2020 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.