2

I have some defined Value Maps as .csv and I want to label features according to this definitions. But when I use simple label expression, labels are "raw values" instead of "description values" - ignore defined Value Maps.

Is there some way to label features correctly?

As a best option, I need to build an expression with several attributes to label like this:

enter image description here

enter image description here

0

1 Answer 1

4

I can reproduce your problem (QGIS 2.18.16).

A working example with a point layer "test" and a CSV-file label.csv.

Alternatively you can use a JOIN:

enter image description here

enter image description here

Or a Virtual Layer:

enter image description here

UPDATE 1

If you have joined a csv to your layer with 3 attributes you can label this way (like the example in the question).

attribute_1 = 'HP
attribute_2 = 41
attribute_3 = 'h'

label expression:

"attribute_1" || '\n' || "attribute_2" || ' - ' || "attribute_3"

With \n as a line break.

Additionally you can change the line height in Labels > Formatting. Also use Center as Alignment to center both lines.

enter image description here

enter image description here

UPDATE 2

When you have NULL values you can coalesce for every attribute:

coalesce( "attribute_1", '') || '\n' || coalesce( "attribute_2", '') || ' - ' || coalesce( "attribute_3", '')

Result:

enter image description here

UPDATE 3

Here is another way to label the features without using coalesce and to get rid of the hyphens when attribute_2 or attribute_3 is NULL.

CASE 
    WHEN  "attribute_1" IS NULL THEN  "attribute_2"  || ' - ' ||  "attribute_3" 
    WHEN  "attribute_1" IS NULL AND  "attribute_2" IS NULL THEN  "attribute_3" 
    WHEN  "attribute_1" IS NULL AND  "attribute_3" IS NULL THEN  "attribute_2" 
    WHEN  "attribute_2" IS NULL THEN  "attribute_1" || '\n' || "attribute_3"    
    WHEN  "attribute_2" IS NULL AND  "attribute_3" IS NULL THEN  "attribute_1" 
    WHEN  "attribute_3" IS NULL THEN  "attribute_1" || '\n' || "attribute_2" 
    ELSE "attribute_1" || '\n' || "attribute_2" || ' - ' ||  "attribute_3" 
END
5
  • Thank you. I edited my question. Filnally I will need several attributes (3 - 4) defined by Value Map to build an expression. Is it possible to do this in Join or Virtual layer?
    – david_p
    Mar 28, 2018 at 7:49
  • You can join multiple attributes to your point vector layer and select multiple columns in the virtual layer selection.
    – Stefan
    Mar 28, 2018 at 7:53
  • Thats exactly what I want! Thank you! Works well! After all, one additional question. What if I build an expression for 3 attributes, like you, but some polygones have only two, third is Null. Its possilbe to include this to expression to label only with two attributes?
    – david_p
    Mar 28, 2018 at 8:22
  • I've updated my answer regarding to the NULL values.
    – Stefan
    Mar 28, 2018 at 9:05
  • 1
    Huh. I thought the represent_value() function was supposed to do what OP had asked for, but I can't get it to work in QGIS 3.0.1. It just puts brackets around the value... it must be some kind of bug?
    – she_weeds
    Mar 29, 2018 at 12:26

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.