0

I would like to produce a series of maps in which each map contains the same layers, with each layer of a given type having the same styling from map to map, but the source of the half of the layers differs from map to map. To be concrete, the map layers would be

  • common_source/layer1
  • common_source/layer2
  • common_source/layer3
  • map_specific_source/layer4
  • map_specific_source/layer5
  • map_specific_source/layer6

All the layers are vector layers. Layer 6 is a 3x3 grid of cells. I need to select the middle cell and extract just that cell to use as the extent for exporting the map. Unfortunately that cell does NOT have the same object ID (or any other field value) that is constant from map to map. Finally, I want to export the map, restricted to that middle cell, as a pdf.

The common source layers and styling can be stored in a template, so that part is easy. But how do I load the map specific layers from the correct source and style them?

I looked at the graphical modeler, but it doesn't seem to be designed for this sort of task. Is there another tool to look at, a way to do this in templates, or do I need to do this in Python?

Edit: I should have mentioned that the map specific layers are grouped together in zip files. This means one approach would be make one map pointing to a zip called something like the_map.zip, then create each new map by copying each zip file in turn over the_map.zip, opening the project, and picking the correct center cell.

4

Matching the Layer Styles

Load all the layers into a single project.

Optional: In the layer panel, organize the layers into groups based on which map they belong on. This is just to help you keep track of which layers go in which map. If you can easily tell where each layer belongs based on the layer name, skip this step.

You can select a layer in the layer panel and copy and paste its style onto another layer. So you only have to style one set of layers 4-6, then copy and paste their styles onto the other matching layers.

Set up the style for one Layer 4. Select this layer 4 > right click on the layer name > styles > copy > all categories. Select all the other layer 4's (hold Ctrl to select multiple layers) and paste the style onto them. Repeat for layers 5 and 6.

Creating a Map Series

The Atlas tool is the go-to method for creating a map series. You will need to create a new layer to control the extent of each map in the series. Since your grid layers don't have any common attributes or information, I don't see any automated way to create the atlas features. You can do it manually as follows:

  • If the extent of each map will always be the same size, you can use a point layer for this. Add a point at the center of each central grid cell.
    • If the maps won't all the the same size, use a polygon layer. Add a square polygon for each central grid cell.

Add a "name" attribute, and give each point a unique name that tells you which map it belongs to. You can later use this attribute as the title for each map.

Set up an atlas in the print layout. Use the layer you just created to control the map extent. Choose the "name" attribute as the atlas page name.

Add other layout items as desired. For example, if you want each map to have a its "name" attribute as a title, add a label item and enter the formula [% @atlas_pagename %].

Use Map Themes to control the layers in each atlas page

Create a separate Map Theme for each map. Use exactly the same names for the map themes as you did for the "name" attribute in the atlas layer. Capitalization, punctuation, spacing and spelling must be identical.

Back in the print layout, select the map item and scroll down to the Layers section of the Item Properties Panel.

Toggle the box next to "Follow map theme". Click on the data-defined settings button: enter image description here. Type in the @atlas_pagename variable. This will set the map theme to match the "name" attribute in the atlas feature for each map page. (This is why you used exactly the same names for the map themes as for the atlas features names.)

| improve this answer | |
  • Thanks for taking the time to write such a thorough answer. While I no doubts this will work, it involves an incredible amount of manual work, defeating the goal of an automated process. As I noted in my update to the question, my map specific layers are grouped in zip files, so by naming the zip files in turn to a common name, I can create a map just by opening the generic qgz file. I still have to pick the right cell to bound the export, but I believe this will be less work per map than the atlas method you outline. – Llaves Apr 28 at 2:48
  • You can change the datasource for a layer through the right click menu (in the layer panel, right click on the layer name > change data source). The new datasource doesn't need to have the same filename as the old one. – csk Apr 28 at 15:16
  • Thanks for pointing that out. However, because all the map specific layers are in a single zip file with the same names in each case, in this very specific instance it is easier to just run a shell script to copy the zip file to a temporary name used in all the maps and then reload the map. This does have a disadvantage that you can't save the project for each unique map, as they all point to the same file. That's not a problem in this case, which is probably an anomaly. – Llaves Apr 30 at 3:49

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.