Dynamic copyright or layer credit in QGIS 3.4?
In QGIS 3.x, go to the View menu > Decorations > Copyright Label.
Insert an expression ...
In the layers group, double-click on the raster layer you want to 'decorate', this will gives its ID
Copy and paste the layer ID in the following expression :
layer_property('raster_layer_ID', 'attribution')
Click
Ok
twice.
Building on J. Monticolo's excellent answer, here's a method that gives attributions for all visible layers.
@map_layer_ids
returns a list (or "array") of the visible map layersarray_get()
returns a single item from a listarray_get( @map_layer_ids ,0)
returns the first item from the list of visible map layersconcat()
combines multiple text strings
For a map with eight layers in the layer panel, use this expression to combine the attributions of all the visible layers, separated with a space:
concat(
layer_property( array_get( @map_layer_ids ,0),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,1),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,2),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,3),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,4),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,5),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,6),'attribution') || ' ',
layer_property( array_get( @map_layer_ids ,7),'attribution'))
Notes:
Add or subtract lines so there's one for every layer in your project. When the expression is evaluated, it only applies to visible layers. By creating sure you have a line for every map layer, you cover every possible combination of enabled/disabled layers.
Note that the array is 0 indexed, so the first map layer has the index value 0, and the last map layer has the index value (total number of layers) - 1
.
You can change the separator between attributions. For example, to use a semicolon, substitute ';'
for ' '
.
Layers without any attribution are omitted automatically. If you see extra spaces in the attribution as displayed on the map, check if any of the layers have a space in their attribution field.