3

I am making a series of maps with the QGIS atlas (print layout composer). I want to show a raster layer on several extents. The extents are defined using a vector layer. The vector layer is used as coverage layer in the atlas configuration. I also crop my raster based on the vector layer.

However I would like a raster legend using a classification symbology that would be dynamic and change depending on the cropping of the displayed extent. In other words, each extent should have its own legend according to the values of the extent.

As symbology of my raster I have indicated that the extent statistics should change according to the actual extent. I use the Singleband pseudocolor as render option. My legend is dynamic when I change the extent in the QGIS project but this is not the case when I change the extent in the atlas. The legend corresponding to the extent in the QGIS project is displayed and not the one that matches the extent displayed in the atlas.

Is it possible to update the extent of the QGIS project (and thereby the legend) according to the extent of each map in the atlas?

I am using QGIS 3.16 but I can use another version if needed. Following diagram illustrates the situation.

enter image description here

And I want my legend to look like this:

enter image description here

1 Answer 1

2
  1. From your coverage polygon layer, create a new layer with Zonal Statics and for Statistics to calculate, select Minimum and Maximum. You get two new attributes with the min/max raster values for each polygon.

  2. Use the new layer as coverage layer. In the legend's raster entry, set the font of min/max value to white to make it invisible. Then add two text fields, one for min, one for max values and position them correctly. The text content is created by an expression that accessses the features created before

    attribute (get_feature_by_id ('zonal',@atlas_featureid),'max' )
    

    zonal is the name of the new coverage layer and max the name of the attribute field containing maximum values.

Now, the values will adapt to the current min/max values of the current atlas feature/polygon.

enter image description here

Output: see two atlas pages: enter image description here

1
  • Thank you for your detailed answer. This alternative is interesting if you only need the min and max in the legend. In my case I need a classification legend. I edited my question to make it clearer.
    – GisUser
    Apr 11, 2023 at 7:02

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.