3

I am creating a world map where I want to make sure that certain countries with an incident are ALWAYS labelled automatically but the other countries are labelled ONLY when there is space to fit the label.

I have created a display field in the table and populated it with

10 - countries where the name MUST be displayed
1 - other countries where the label should show if it doesn't overlap.

Based on QGIS label priority settings I have created a statement

enter image description here

I understand that this won't work but I need to be able to say

Case when
 "Display"=10 then "CNTRY_NAME" - must display
 "Display"=1 then "CNTRYY_NAME" - should display when not overlapping

How do I achieve this in v3.12 without having to duplicate the layer and creating a filter where the labels are shown even when overlapping (filter display=10) and do not overlap (filter display=1)

2
  • 3
    What about using the "Rules-based labeling" option rather than the "Single Labels" option in the layer's label type? This way you may establish sets of rules without duplicating the layer. – CrystallineEntity Apr 10 '20 at 4:54
  • 1
    For labels that must display that should be defined in 'Always show', not 'Show label'. And have you tried using the Priority settings anyway, with Display driving it? The post you link is from a much older version of QGIS and it probably works better now (in conjunction with the always show option). – she_weeds Apr 10 '20 at 5:10
4

As been said in the comments, there are more option how to achieve this. If you want to use simple data defined rendering you should use Always show parameter as @she_weeds sugests.

Keep in mind that the expression result should be 1 - True or 0 - False (this also applies to Show label). You can see the expected output in expression window or you can check this in the description when you open the data defined override button context menu.

In your case you can use:

CASE 
    WHEN display = 10 THEN 1 
END

and it results to: g

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.