2

Using QGIS` atlas feature, how can I pass information from my coverage layer to the layer's rendering engine?

At the moment, I'm abusing the Page name in the Layout > Atlas tab like this:

"country_code" || '-' || "my_custom_field"

In the "Labels" section in my layers I can now access this information using the variable @atlas_pagename.

Lets assume I have this coverage layer:

country_code my_custom_field
US 1.0
FR 2.0
LU 3.0

Now, @atlas_pagename has these values...

US-1.0
FR-2.0
LU-3.0

... and I can use the variable in my Data defined override settings using something like to_real(substr(@atlas_pagename,4)).

The problem with this approach is every time I want to access the value of my_custom_field, I have to parse the needed information. And I can't use the page name variable for its intended use anymore.

So, how can I set a variable in my atlas configuration with the value of a field in my coverage layer?

3
  • 2
    Hi, your question is about how to define a new atlas variable, but can't you get the attribute of the atlas feature with attribute(@atlas_feature, 'my_custom_field')? Commented Nov 20, 2023 at 14:48
  • 1
    @GabrielDeLuca Yes and no. My question was how to access a field from the coverage layer. I somehow thought that I had to do some setup to access this data. From your comment I learned that I just can to use attribute(@atlas_feature, 'my_custom_field') in my Data defined override expressions. Case closed. (If you provide your comment as an answer I'm happy to accept it.)
    – z80crew
    Commented Nov 20, 2023 at 15:21
  • You don't even need to use attribute(), you can just directly reference the field name in any expressions (i.e. "my_custom_field") As a bonus, that's case insensitive unlike attribute()
    – she_weeds
    Commented Nov 21, 2023 at 7:27

1 Answer 1

2

There is no need to store the attributes of the coverage layer in an atlas variable, because a reference to the coverage feature of the current atlas page is stored in the @atlas_feature variable.

So you can call its attributes from any expression in the project, with the attribute() function, like:

attribute(@atlas_feature, 'my_custom_field')

Your Answer

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

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