2

I wanted to display the labels (which only 8 labels with the longer names)from one field. I've tried in multiple ways but wasn't works (NOT duplicated question)

I've tried this: if ("NAMEASCII"='Nikolajewsk na Armur', 'Nikolajewsk-\nna-Armur',NAMEASCII)

[I've tried CASE statement, in my case works better only with IF statement]

The result of this expression (green: is the result, red: I need to do the same for this as well): enter image description here

Layer properties > Label > Rule: enter image description here

Label with: enter image description here

BUT this is only one of them, there have 8 labels that I need to create the expression together (i don't know how to combine these 8 names only with one expression) just after the expression(above) Can anyone tell me how? I may need a correct expression... because qgis giving me a syntax error, obviously, the expression that I created is wrong.

7

Your initial attempt is invalid because you have no quotes around the 2nd `NAMEASCII". So it should be:

if( "NAMEASCII"='Nikolajewsk na Armur', 'Nikolajewsk-\nna-Armur',"NAMEASCII") 

But a better solution might be something like:

if(  length( "NAMEASCII")>10,  wordwrap( "NAMEASCII", 10, '-'),"NAMEASCII") 

where the wordwrap function

Returns a string wrapped to a maximum/minimum number of characters.

Syntax wordwrap(string, wrap_length, delimiter_string)

Arguments

string the string to be wrapped

wrap_length an integer. If wrap_length is positive the number represents the ideal maximum number of characters to wrap; if negative, the number represents the minimum number of characters to wrap.

delimiter_string the delimiter string to wrap to a new line (optional).

  • @Sigrid, @ JGH, @ Ian Turton, THANK YOU SO MUCH GUYS! Problem solved :) – ndr May 4 '18 at 11:22
4

I can see you are working with rules (Regel). You can choose Formatting and choose wrap on character: '-'

Then add the '-' in your data for these 8 labels. enter image description here

  • Hi, thx for replying, I've added one more screenshot which is the 'rules', I have 3 rules here, and I've tried to make another rule for only these 8 labels (created one column called "name_long"), but unfortunately it doesn't display on the map. YES, I did it like you've posted just now (on 'Wrap on character' box), but nothing changed. – ndr May 4 '18 at 10:46
  • These 8 populated places: Is it all there is in this layer, or do you have more populated places? – Sigrid May 4 '18 at 10:52
  • If you have more populated places and only want to show labels for these 8 places, you could add a field used for filtering the labels. Then I'd give these 8 places the same value. – Sigrid May 4 '18 at 10:56
  • These 8 of them are part populated places, and all these 8 in this layer. I need a correct combined expression for these 8 only, which will be filled in "Wrap on character" but not '-' (i think..) – ndr May 4 '18 at 10:59
  • @ Sigrid i want to show labels for all cities/ points, but these 8 has longer name than others, so the labels of all points need to be shown include these 8 which have longer name – ndr May 4 '18 at 11:05
4

Instead of using an if expression, you can use a case

CASE 
   WHEN "NAMEASCII"='Nikolajewsk na Armur' THEN 'Nikolajewsk-\nna-Armur'
   WHEN "NAMEASCII"='other name to modify' THEN 'A-B-C' 
   ELSE "NAMEASCII"
END

Alternatively, you can go to the text tab of the label, and check Apply label text substitutes at the bottom and click the ... to the right. There, you can define the text to be changed.

Label - text substitution

Label - text substitution - rules

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.