I'm in a course learning about GIS systems, and we have recently recorded a GPS track. I've exported this track as .gpx and imported the points into QGIS.

Each point has a timestamp. One of the things I'm interested in is finding the temporal resolution of my file, thereby needing some sort of 'delta time' between each pair of points.

So, what I want to know: How to do calculations between different points in a vector layer? I'm not experienced in Python (but MatLab would be possible I guess), so I'd like to do it with the field calculator.

3 Answers 3


If you would like to calculate from values in different rows of your data, you should open your data source twice in QGIS and make a join between the two copy of the same layer. In your case it is a bit more complicated because QGIS allows only equi-join, not like first_table.id = second_table.id-1. So make two copy of your layer in shape format sorted by time and set id-s to be useful for join. I would load data into a database (SpatiaLite or PostGIS) and use SQL.

  • Seems like a solution, just ofsetting one of the two copies seems like a very simple solution looking back. Jun 11, 2017 at 11:29

If you have access to PostGIS as a backend, then you can use the lag() window function, which solves exactly your problem, i.e. using the value of a previous record in the calculation of the current record.

Assuming your points layer has the timestamp_ field. The SQL would be something like this:

SELECT timestamp_ - lag(timestamp_) OVER () AS tdiff 
FROM points ORDER BY timestamp_;  

The lag() over() function returns the previous row, which is the previous timestamp_ because of the ORDER BY timestamp_ clause.

You can run the query either directly in PostreSQL or via QGIS's DB Manager plugin (after importing your points into PostGIS directly or via QGIS).

  • I have never used PostGIS, but I will consider this answer when I encounter this type of problem again. Thanks! Jun 11, 2017 at 11:31

If it is a gpx track, the points should be in order, so you can just walk the track and compare the timestamps of the two adjacent points and output point1id, point2id, deltatime fields to a table. You could actually do in python working directly on the gpx track without messing with qgis.

  • Yeah, that's what I thought. I can do it also easily in Matlab, but the general question of using previous points in calculations of the current point has come up before, so I wondered if there was a way to do this. Anyway, thanks! May 4, 2015 at 15:12

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.