QGIS Print Composer – Displaying Attribute Names Efficiently

print-composerqgis

I'm using QGIS 3.16 Hannover and I've got a vector layer of provinces with animal species names as attributes. If the species has been detected in the province, the value of the attribute is X; if there are breeding records, the value is R; otherwise the value is NULL.

I'm producing a map for each species and I'm using the categorized layer style for displaying the provinces where the species is present. Is there a way of automatically display the selected attribute name (i.e. the species) in the print composer?

enter image description here

Best Answer

I think that Atlas feature is what you seeking for (see Documentation). For this case I have a workaround with Atlas. Trick is that instead of iterating through geometries I use list of former field names (species names):

  1. Create .csv with field names in one column and load it into QGIS enter image description here

  2. Set this csv layer as Covarage layer in Atlas settings (layout window) and as Page name choose the column with the species names. enter image description here

    The Page name will be used to identify the atlas page, and also its values can be referenced in expressions using the @atlas_pagename variable. You now have the Atlas set up that will generate one page for each species name.

  3. Set the polygon layer symbology - as Value for categorized symbology use this expression: attribute(@atlas_pagename)

    The attribute() expression returns value of attribute of given field name (i.e. attribute('species_1') returns the same result as when you directly select the attribute species_1). However, we need this value to change (species_1, species_2 etc.) according to the page of the atlas. Thus we have to use @atlas_pagename variable which returns value of page name of current atlas feature. This causes iteration through the fields of the polygon layer because their names are identical to those in the Page name of the Covarage layer (csv table) used in atlas.

    Now you have to manually add the two categories and set their symbols (other solution is use of Rule-based symbology with expression such as attribute(@atlas_pagename) = 'X' and so on)

enter image description here

  1. Prepare your layout. For displaying the species name just add text (Add Label) and select the name of the field with species names.

enter image description here

Preview the result:

enter image description here

Related Question