In this post, we use TimeManager to visualize the position of a moving object over time along a trajectory. This is another example of what is possible thanks to QGIS’ geometry generator feature. The result can look like this:

What makes this approach interesting is that the trajectory is stored in PostGIS as a LinestringM instead of storing individual trajectory points. So there is only one line feature loaded in QGIS:

(In part 2 of this series, we already saw how a geometry generator can be used to visualize speed along a trajectory.)

The layer is added to TimeManager using t_start and t_end attributes to define the trajectory’s temporal extent.

TimeManager exposes an `animation_datetime()`

function which returns the current animation timestamp, that is, the timestamp that is also displayed in the TimeManager dock, as well as on the map (if we don’t explicitly disable this option).

Once TimeManager is set up, we can edit the line style to add a point marker to visualize the position of the moving object at the current animation timestamp. To do that, we interpolate the position along the trajectory segments. The first geometry generator expression splits the trajectory in its segments:

The second geometry generator expression interpolates the position on the segment that contains the current TimeManager animation time:

The WHEN statement compares the trajectory segment’s start and end times to the current TimeManager animation time. Afterwards, the line_interpolate_point function is used to draw the point marker at the correct position along the segment:

CASE WHEN ( m(end_point(geometry_n($geometry,@geometry_part_num))) > second(age(animation_datetime(),to_datetime('1970-01-01 00:00'))) AND m(start_point(geometry_n($geometry,@geometry_part_num))) <= second(age(animation_datetime(),to_datetime('1970-01-01 00:00'))) ) THEN line_interpolate_point( geometry_n($geometry,@geometry_part_num), 1.0 * ( second(age(animation_datetime(),to_datetime('1970-01-01 00:00'))) - m(start_point(geometry_n($geometry,@geometry_part_num))) ) / ( m(end_point(geometry_n($geometry,@geometry_part_num))) - m(start_point(geometry_n($geometry,@geometry_part_num))) ) * length(geometry_n($geometry,@geometry_part_num)) ) END

Here is the animation result for a part of the trajectory between 08:00 and 09:00: