3

I have a group of city in a small area with labels. Due to label engine it shows them in a 'random order' (and certainly optimizing) according the space the have.

There is a way, without duplicate the layer, to prioritize just ONE city name to be show whatever the conditions are, the others showed cities order around doesn't matter.

3

You can use a conditional expression as you label:

CASE WHEN "MyCitynameColumn" = 'New York' THEN 
    MyCitynameColumn 
END

You can have more than one Case and combine with a Else statement:

Syntax

 CASE
    WHEN condition THEN result
    [ ...n ]
    [ ELSE result ]
 END

[ ] marks optional components

If you have a lot of small areas, resulting in too many cases, your better of using two layers for labeling.

Also you could add a column like Showlabel, fill it with 0 or 1, and use that in the expression

CASE WHEN "ShowLabel" = 1 THEN 
    "Vejnavn"
END

Or you can use an in function in a Case statement:

Case When "MyCitynameColumn" in ('Nibe','New York') then
    "MyCitynameColumn"
End 
  • Thx, but I just want to prioritize a city, not hide the others. we will use different zoom level at the end (9 to 13). – Mathieu May 11 '15 at 10:00
  • Thx Jakob but my area is not a small one, it is Europe ;-). So we just need to manage some exeptions (only few). I understand perfectly your way. But in our case is not manageable. – Mathieu May 11 '15 at 10:12
  • It is not possibly to databind to the prioritize function. The closest I can think of is to databind a column to both ShowLabel and Always Show label under the rendering tab. – Jakob May 11 '15 at 10:14
  • 1
    In previous mapping job I have done, I have used the duplicate layer, that you do not like, for jobs like this :) – Jakob May 11 '15 at 10:16
  • We try to create an other style inside the layer and filtering the cities name we want in. We put this in higher layer order. But doesn't work. Maybe can be a trik in the labels function, but this out of our knowledge. So we made a turn around : we have an other layer for capital. So we downgrade those cities in capital order (OSM tag) then this work. – Mathieu May 11 '15 at 16:28
2

It seems this may be possible in 2.14 and above.

The Priority attribute in Labels > Placement allows you to Edit... an expression for the value. As in the picture below, it seems the Priority variable ranges from 0.0-10.0, and thus whatever expression you come up with should be in that same range.

enter image description here

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.