1

How can I set the title of a QGIS map based on a name I pass in a .csv file?

I create a separate file 'tombstone_data.csv' that contains two fields like this:

source,update_rate
FlightRadar24,1 x per 3 sec

however I cannot find out how to use the source field (= 'FlightRadar24') as the title of the map.

2
  • have you imported the CSV as a table in the map, or are you trying to read it from file?
    – Matt
    Commented Jan 28, 2022 at 14:38
  • imported the CSV as a table. Could as well read it from a file if that is easier. Commented Jan 29, 2022 at 13:12

1 Answer 1

1

You can use an expression for the Label item text.

enter image description here

Then use:

attribute(get_feature_by_id('myCsvLayer', 1), 'source')

It finds the attribute value from the feature with id=1 in the source field of the layer called myCsvLayer.

You will see that once you click OK the label text is wrapped in [% %]. This is so it evaluates as an expression.

[%attribute(get_feature_by_id('myCsvLayer', 1), 'source')%]

enter image description here

If you want to identify a feature using an attribute value (like a unique code that exists in your attribute table) use get_feature rather than get_feature_by_id:

attribute(get_feature('myCsvLayer', 'fieldName', 'fieldValue'), 'source')

Note:

I noticed when I was testing that if you add a CSV via Layer > Add Layer > Add Delimited Text Layer the feature id starts at 2 which I think must be a bug.

A CSV layer added by dragging it directly into the map canvas starts at 1.

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.