2

I'm attempting to produce a series of maps in QGIS, each showing a different layer overlaid over the same region, each with an associated different title and legend to match each layer. I'm stuck with trying to figure out how to extract the name of each map based on the specific layer shown.

For example, one layer is named Opt1_00010Y_Critical_h_Max, and I want to be able to extract a text box to the print layout that will draw out the Opt1, 00010Y and h_Max elements to create a map label saying Option 1, 10 Year, Flood Depth. And then to be able to set up a function that will do this for each map automatically.

1
  • I would suggest that doing themes and using the theme name would be the best option. It could be done in theory with pygis, but with expressions only you lack a way to exfiltrate what you want from the map to something else. As the map has function to enumerate layers and to validate their state (is_layer_visible).
    – Al rl
    Jul 1, 2022 at 10:56

1 Answer 1

1

There is two part in your project : create atlas that create one map for each of your layer, then adapt the text to match the needs you have.

For the first part there is a solution explained here : https://gis.stackexchange.com/a/395333/145110

For the second part, you have to create an expression to extract what you want to show and add it in your atlas table to make it work. In your example you have to add a field Option_number, number of year, Label.

The fields could be virtual field :

  • For Option_number the expression could be to_int(substr("layer_name", 3),1))
  • For number of year the expression could be to_int(substr("layer_name", 6),5))
  • For Label the expression could be substr("layer_name", 13)

Then you can add a text zone in your layout to show your complete text.

 'Option '|| "Option_number"  || ', '  ||  "number of year" || ' Year, '  ||  "Label"
6
  • Using themes would be more efficient than handling separate maps for each as you'll have to toggle layers for each export.
    – Al rl
    Jul 1, 2022 at 10:32
  • Depend how many maps you have. For 3-4 maps, themes are easier… but I have the case to create 64 maps, and themes are way to long to create!
    – katagena
    Jul 2, 2022 at 15:01
  • @Alrl no need to toggle maps layer for each export. It is explained in the first part (just click on the link). Jul 4, 2022 at 13:07
  • @CorentinLemaitre right I see, though I would suggest that instead of having a static string hidden in an expression, it could be simpler to store them as attributes in the atlas, maybe even doable as a virtual layer. But that's a good approach.
    – Al rl
    Jul 4, 2022 at 22:48
  • You are right. I will add an edit to get it as a virtual field, but I really don't know how to do. If you know how to do then you can add your own answer. Jul 6, 2022 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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