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?
1 Answer 1
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')
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.)attribute()
, you can just directly reference the field name in any expressions (i.e."my_custom_field"
) As a bonus, that's case insensitive unlikeattribute()