16

Is there a way to label a layer using its file name or layer name (if I'd change it in Layers window TOC)? I tried some functions but I'm not good on that.

I have lots of shapes (lines) and it would be easy to identify them this way. Of course, this name could be a table attribute but I'm trying a alternative way (maybe more dynamic).

1
  • Very good question but I do not think it is supported (yet). You could request this as a new feature here by registering and posting a new request form.
    – Joseph
    Commented Oct 20, 2014 at 11:18

2 Answers 2

12

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.

3

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

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.