5

I have prepared my page layout in print composer, and in my title i want to generate a dynamic texts which is related to an attribute layer which i have filtered previously.

For example:

I have layer1(this layer has only one row after filtering) with attributes att1,att2,att3 I want a dynamic in my composer that puts a text label att1-att2 or just only att1

This is a screenshot of my layer and their attributes which from i want to make dynamic text.

enter image description here

6
  • do you want the field name or the value of the attribut ? Commented Oct 26, 2017 at 12:46
  • for the moment i need the value of the attribute, it would be nice even to know how to add layer name, field name or attribute and the possibility to combine different field attribute for example CZ||'-'||CZ_NAME Commented Oct 26, 2017 at 13:08
  • 1
    have you look into attribute table module under composer : gis.stackexchange.com/questions/243104/… Commented Oct 26, 2017 at 13:52
  • 1
    or maybe what you need is to make an atlas ? Commented Oct 26, 2017 at 13:59
  • Please note that a good question on this site is expected to show some degree of research on your part, i.e. what you have tried and - if applicable - code so far. For more info, you can check our faq. Commented Oct 26, 2017 at 14:03

1 Answer 1

3

When you wish to display attribute values from your layer using a text label, you can define an expression that references the attribute name. For example, if you need the value of the CZ_NAME attribute from your coverage layer (the one set as such in the atlas settings), you can use:

[%"CZ_NAME"%] 

If you want to concatenate this value with another attribute or text, you can do so with the following expression:

[% concat("CZ", '-', "CZ_NAME") %] 

In addition to this standard approach, you may want to dynamically retrieve data from a secondary data source. This is where the aggregate function comes into play. Suppose you need to display dynamically the sum of the burned area (attribute superficie_indic_ha) from a thematic fact table such as vue_dtm_zb_administ. This table is filtered according to both spatial and temporal dimensions. When you want this in Atlas, this is realy powerfull. The spatial filter uses the @atlas_pagename (from the atlas coverage layer) and the temporal filter relies on the environment variable ATLAS_YEAR. The corresponding QGIS expression for the filter might look like:

id_spatial = @atlas_pagename and year = env('ATLAS_YEAR') 

Then, using the aggregate function, you can sum the values as follows:

aggregate( layer := 'vue_dtm_zb_administ', aggregate := 'sum', expression := "superficie_indic_ha", filter := type_spatial = 'commune' and id_spatial = @atlas_pagename ) 

Explanation

  • Text Label Approach:
    You simply reference the attribute by enclosing its name in the expression syntax ([%"CZ_NAME"%]). You can further manipulate the output, for instance by concatenating strings or additional attributes.

  • Aggregate Function Approach:
    This method allows you to pull in data from another layer or table (in this case, a thematic fact table). The parameters include:

    • layer: the data source ('vue_dtm_zb_administ').
    • aggregate: the type of aggregation operation (here, 'sum').
    • expression: the field you wish to aggregate ("superficie_indic_ha").
    • filter: conditions that limit the data aggregated (using both spatial and, if needed, temporal filters like year from env variable for exemple).

This dual approach empowers you to dynamically incorporate and aggregate data from multiple sources, ensuring that your atlas pages can display up-to-date and contextually relevant information based on spatial and temporal parameters.

7
  • What about relating to other layer, is it possible? Commented Oct 28, 2017 at 8:49
  • happy to help. I am sorry, I don't understand what do you mean exactly, please ask a new question for this specific use case. Commented Oct 28, 2017 at 9:03
  • No, its related to the same topic so im not opening another question. What i meant is what if i want to take attribut not from coverage layer but from another layer in the layer panel Commented Oct 28, 2017 at 9:13
  • I'm wondering the same as you @ShefqetLULJA. Did you happen to find out? Commented Jun 24, 2019 at 10:22
  • You mean, you want to concatenate attributes from 2 different layers ? you should create join or relation on the QGis layer/project before. Then you wil get attributes on the coverage layer. Commented Jun 27, 2019 at 23:57

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.