QGIS – Creating Animated Lighthouse Light Cone and Covered Coastline in QGIS

animationgeometry-generatorpointpolygonqgis

As a follow up question to this: Hiding layer for N seconds in QGIS: animate symbols with custom intervals

Using QGIS 3.32, how can I animate a point layer using the new animated marker style in a way that a light cone (simulating the light of a lighthouse)

  • rotates with different speed for each point and that
  • the part of the coastline that is currently covered by light is highlighted

This should be possible using Geometry generator symbol layer, but how can it be implemented?

Best Answer

Before starting, make sure your point layer contains an attribute speed that contains values for the speed of the light cone for each lighthouse (point).

Framerate of 20 fps, left point with speed of 2, right with 3. Yellow cones/wedge buffers represent light, red lines mark the areas of the coastline currently covered by light: enter image description here

  1. Set the point layer representing the lighthouses to animated and define a frame rate (e.g. 20 fps) as described here:

  2. Create the light cone by adding a new symbol layer of type Geometry generator > Polygon and add this expression. "speed" in line 3 defines the varying rotation speed depending on the value in the attribute, the parameters (width and radius of the cone) can be changed in lines 4 and 5:

     wedge_buffer( 
         $geometry,
         @symbol_frame * "speed" % 360,
         20,  -- change width of the cone
         1200  -- change radius of the cone
     )
    
  3. Create another Geometry generator symbol layer with this expression. Replace land with the name of the polygon layer prepresenting the landmass. Values for cone's width and radius must match the ones in the expression before. Alternatively, use layer variables for this, so you don't have to match the values manually in both expressions.

     collect_geometries(
         array_foreach(
             overlay_nearest (
                 'land',  -- adapt layer name
                 $geometry,
                 limit:=-1
             ),
             intersection(
                 boundary (@element),
                 wedge_buffer( 
                     $geometry,
                     @symbol_frame * "speed" % 360,
                     20,  -- change width of the cone
                     1200  -- change radius of the cone
                 )
             )
         )
     )
    

Geometry genertor of step 3, creating the red lines: enter image description here

Related Question