QGIS – Creating Animated Line Moving Between Points

animationdatetimelineqgistime

I have a point file, with Date:Time enabled. Rather than just animate the cycling through of points, I would like to have a line moving in a straight direction from one point to another in date order.

What would be the best way to go about this?

Based on Babel's answer I have tried the following:

with_variable (
    'zone',
    0,  -- change this value to add/subtract hours to/from attribute named arrival_time to transform local time zone to UTC
    with_variable(
        'arrival',
        Date_time + to_interval (@zone  || ' days'),
        with_variable(
            'next',
            attribute (get_feature_by_id (@layer, $id+1), 'Date_time'),
            with_variable (
                'mapstart',
                @map_start_time + to_interval ((second (@map_end_time - @map_start_time)/2 ) || ' seconds'),
                with_variable (
                    'line',
                    make_line (
                        $geometry,
                        geometry( get_feature_by_id (@layer, $id+1))
                    ),
                end
                )
            )
        )
    )
)

My data contains a Date-time column of the format YYYY-MM-DD HH-MM-SS. With a few exceptions all are set to 13:00:00 for the time, which is not so important. The only time this is different is when I have rows of the same day, and so would then control for them with different times.

Best Answer

I have a point layer with two fields :

  • id : unique integer field
  • dt_field : date time field, format yyyy-MM-dd HH:mm:ss

I just created a symbol layer for the point layer with geometry generator symbol type, linestring geometry type.

As geometry generator expression, I wrote the following code :

with_variable('data', array_agg("id", order_by:="dt_field"),
with_variable('id_index', array_find(@data, "id"),
with_variable('next_feature', get_feature(@layer, 'id', array_get(@data, @id_index + 1)),
    make_line($geometry, geometry(@next_feature))
)))
  1. I created an array with id field values ordered by the Date Time field @data
  2. I retrieved the current feature id index position in the @data array
  3. I searched for the next Date Time feature, so the feature that is next in the @data array (or @id_index + 1) : @next_feature
  4. I created a line starting from the current geometry $geometry (use @geometry since QGIS 3.28) to the next feature geometry geometry(@next_feature)

With temporal controller activated and the point layer temporal settings sets on the dt_field, you can see the line moving through the time.