QGIS – Automating the Creation of Multiple Maps with Different Layers on Same Location in QGIS

atlasmapsqgis

I was wondering if it is possible in QGIS 3.2 to cycle through different layers.

For example, I have a workspace open with 3 raster layers (A, B and C). I would like to create 3 maps:

  • Map A with Layer A and Legend A
  • Map B with Layer B and Legend B
  • Map C with Layer C and Legend C

The only difference in all these maps is the switching of the raster layer and the legend of the layer. Everything else is the same.

I found a similar question before but it appears to be unanswered.

Creating atlas of different layers on the same place (QGIS)

Best Answer

You can set layer visibility (in the layer symbology) based on an atlas variable. Your options for atlas variables are: @atlas_feature, @atlas_featureid, @atlas_geometry and @atlas_pagename.

In QGIS 3.0, use the atlas variable to control whether the layer is enabled.

For example, if your atlas pages are named Map A, Map B and Map C, set the visibility of the grid for Map A like so:

enter image description here

In QGIS 2.18 and earlier, "Enable layer" is not an option. Instead, use a similar method to control the layer transparency. Use this expression for data-defined transparency for Map A:

if(@atlas_pagename = 'Map A', 0, 100)

You can also write your own expressions to control layer visibility within the print composer. enter image description here

Write an expression that outputs a list of map layer names separated by the | character. For example:

case 
  when @atlas_pagename = 'Map A' then 'layerone | layertwo | layerthree'
  when @atlas_pagename = 'Map B' then 'layerone | layertwo | layerfour'
  when @atlas_pagename = 'Map C' then 'layerone | layertwo | layerfive'
  else ''
end

enter image description here This is how I knew how to format the list of map layer names.