0

Hope to obtain: sample expressions for printing each visible layer of a project using Print Layout's Atlas functionality

Based on @Erik's comments on another question (about changing QGIS behavior), I'm trying to follow through on setting up printing an "atlas."

The dialog (below) is imposing for a neophyte. The first reference returned from a search on 'atlas' in the QGIS docs is to an Example, which nevertheless is enough different from my scenario as to not shed light.

It focuses on using a vector layer composed of an array of rectangles to print a set of smaller maps covering a single layer.

In my application, I wish to use a layer with a single rectangle to print a set of maps for the same region from each of a set of 4 layers. (Erik had also suggested perhaps using a Map Theme to reference all the visual layers, but I do not find any reference to a map theme among the items available in "Expressions.")

Beyond opening Atlas->Settings in Print Layout, selecting "Generate an atlas", choosing my "Coverage layer" (with the vector layer containing my polygon), and hiding that coverage layer (so the polygon won't print on the outputs), I'm lost.

In particular, I'd like to know how to fill out:

  • Configuration->PageName, ->FilterWith, and ->SortBy fields
  • Output->OutputFilenameExpression field.

I'd also like to know how to get a list of the visible layers and how to step through them in Expressions Dialog (which comes up when clicking on the side-button of the PageName field). If using a map theme is the way to go, how is it referenced in the Dialog?

Thank you.
atlas dialog

5
  • Have you clicked the button to preview the atlas? Or tested exporting it and looked at the output? Your question seems a bit broad, and it's not clear in what ways the atlas as currently configured is falling short of your expectations. – JoshC Jul 14 '20 at 16:00
  • I'm not quite sure what you want to do: you want to print several times the same map canvas but each time with only one layer visible? Like map 1: layer 1, map 2, layer 2...? In the expression builder, under variables you have variable map_layers - output is a list of visible layers in the map. You the middle column also have a section called map_layer - when you expand it, you can select from there all layers of your project. And if you select the map in your atlas layout and go to element properties - layer - follow map theme, on the right side you can click the data driven override. – Babel Jul 14 '20 at 16:20
  • Your screenshot shows the atlas generation dialogue. There, you define the coverage layer, thus the grid that creates your atlas pages or the administrative units each of which should be output as a separate page. The coverage layer defines the canvas extent of the map, not it's content. If I understood you well it is not the canvas extent that you want to change - you want to set the definition of what is visible on each map of your output (like let's say rivers, roads, buildings, trees etc.). Thus you have to go to the element properties. – Babel Jul 14 '20 at 16:26
  • Have a look here to see if that helps: docs.qgis.org/3.10/en/docs/user_manual/print_composer/… It says: "Locked layers in the map item can also be data-defined, using the using the dataDefined icon beside the option. When used, this overrides the selection set in the drop-down list. You need to pass a list of layers separated by | character. The following example locks the map item to use only layers layer 1 and layer 2: concat ('layer 1', '|', 'layer 2') – Babel Jul 14 '20 at 16:45
  • @babel "I'm not quite sure what you want to do: you want to print several times the same map canvas but each time with only one layer visible?" Exactly. – quagmire Jul 18 '20 at 11:47
2

This solution here is kind of a hack, there might be better solutions: If you want to use a grid of rectangles (polygons) and print a separate map-page for each rectangle, set this rectangles-layer as coverage layer in your atlas generation tab (your screenshot).

To have four different maps with each showing a different layer for every rectangle, than create 4 pages in you atlas layout (create one page with the map and than add more pages and copy/paste the elements of the first page). Than on each site set another map theme that your map element should follow. You have to define first these four map themes in the QGIS main window - create four map themes with each showing just one layer.

Another hack, maybe a little bit more elegant: duplicate the rectangles in your coverage layer so that you have four times the same rectangles in the same layer. Than define the four map themes. In the layout, you now have to create just one page for the atlas. For the map theme, use a data driven override with an expression like this:

if ((@atlas_featurenumber  % 4 =0),
        'theme_4', 
       if ((@atlas_featurenumber  % 3 =0),
               'theme_3',
               if ((@atlas_featurenumber  % 2 =0),
                      'theme_2',
                          'theme1')
))
3
  • I cannot grasp the process in my head, but have a good feeling that what you propose will work admirably. '%' I take it is modulo, in order to step through the features? That in itself is a gift as I had looked vainly for 'for, while, do, case' statements. – quagmire Jul 18 '20 at 11:44
  • Exactly, % is modulo, so you have three if-clauses: if the atlas feature no. is 4, 8, 12, 16 and so on, apply theme 4; otherwise - next if-cluase: if atlas featur no is 3, 6, 9, [12 is excluded because of the first if-clause], 15 etc. and so on. Be aware however that you have your duplicated rectangles from the coverage layer ordered accordingly. Don't use the fid: when you duplicate, new fid's will be created and the new features will get the highest no. and thus be the last ones to be rendered by the atlas. – Babel Jul 18 '20 at 13:18
  • If you have a unique field in the coverage layer (like a name or a no) that will be duplicated, thus having 4 times the same value, you cand order the atlas by this field. This is to get all 4 outputs (for the different layers you want to represent in the atlas) together - without that, themes 1 to 4 apply to neighboring rectangles, but you want it to apply each time to the same rectangle. – Babel Jul 18 '20 at 13:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.