5

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?

1

1 Answer 1

2
+100

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

4
  • In case we'd need to use on/off periods shorter than 1 second, would this still be valid or should we change the fps accordingly? For example, if we have a light whose period goes on and off for 0.5 and 2 seconds.
    – Trikelians
    Oct 31, 2023 at 22:54
  • I would change fps. See also here how to deal with milliseconds: gis.stackexchange.com/a/469355/88814
    – Babel
    Oct 31, 2023 at 22:59
  • @symbol_frame % 2 results in 0/1 (true/false or visible/not visible = blinking) and fps set to 2 results in 2 frames per second, one visible for 0.5s, one not visible for 0.5s = blinking (one look in 1 s). For 2 seconds, set frame rate to 0.5 etc.
    – Babel
    Oct 31, 2023 at 23:07
  • 1
    For a project in which the patter is 0.5 s on, 2 s off, 0.5 s on again and then 6 s off for a total of 9 seconds, I had an hybrid approach between this and your other method: I multiplied the values by 2 in order to get whole numbers and using this expression with a framerate of 8 fps, it works good. The only problem is the already mentioned issue with the refresh rate affecting other layers. However, I cannot adapt it to a framerate of 1 fps, as the animation renders too slow. @symbol_frame/4 % 18 > 0 AND @symbol_frame/4 % 18 <= 1 OR @symbol_frame/4 % 18 > 5 AND @symbol_frame/4 % 18 <= 6
    – Trikelians
    Nov 10, 2023 at 7:42

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.