QGIS – How to Hide Layer for N Seconds and Animate Symbols with Custom Intervals

animationexpressionqgissymbologytime

This is a follow-up to Making geometry blink in QGIS, for which I couldn't find any answer online.

It is relatively simple, using the Time Manager plugin or the Temporal Controller native tool in QGIS, to animate (display) a layer for a certain amount of seconds.

But how would we control it if we want that layer to be hidden for another N amount of seconds?

Let's say we have two layers that represent two lighthouses, and we want to recreate the pattern of its blinking lights:

Assuming they both start at the same time, but one is on for 4 seconds and off for 1 second, and the other is on for 5 seconds and off for 5 seconds, how would we animate this and make the animation loop forever?

Is there any expression that would be useful in the Geometry Generator?

Best Answer

As mentioned by @MrXsquared, there is a new Animated Marker since QGIS 3.26. This works even without Time Manager plugin or the native Temporal Controller. See this follow up question for what more complex use cases you can use it.

Proceed as follows (screenshots and animation for demonstration below):

  1. In the Layer Styling, select the top level of the symbol Marker, go to Advanced > Animation Settings... and set a Frame rate of 1 fps (frames per second). Make sure the Is Anmimated box is checked.

  2. Back in the the Layer Styling, select the Simple Marker entry and go down to Enable symbol layer and click data defined override (icon ɛ).

  3. To make the symbol be on/off for 5 seconds each, add the expression @symbol_frame % 10 < 5. Proceed the same way for the other layer, to be on for 4 and off for 1 second, use @symbol_frame % 5 > 0.

Or, even better, if both symbols are on the same layer, to animate the point with id=1 for 5/5 seconds, the other one for 4/1 seconds, use this expression:

case 
when id = 1
then @symbol_frame % 10 < 5
else @symbol_frame % 5 > 0
end

enter image description here

enter image description here