Is there a way to label a layer using its file name or layer name?

Since QGIS 2.12 you can use the following expression to print the layer name:

layer_property( @layer_id, 'name')

You can lookup further properties in the documentation of the layer_property function in the expression editor.


Bonus answer: if you try layer_property( @layer_id, 'name') but your layername is a little bit long to work as a label, you can split that up over multiple lines:

Say your layer name is: 'Gibbs_ID1730544_A9056_TRRS_Harvest'

You can split it over multiple lines using wordwrap like this: wordwrap(layer_property( @layer_id, 'name'), 15, '_') which specifies you want to get the layername, split it on the _ character and keep each line to a max of 15 characters long.

The result: you get these four strings over four lines:

Gibbs ID1730544 A9056 TRRS_Harvest

Tags:

Labeling

Qgis