I have a layer of places with their name and population data. I'd like to dynamically label the places in QGIS: draw a label if it wouldn't cover up or hide the label of another feature with a bigger population.

So in the countryside, I might want a tiny village to show up, but not a village of the same size right next to the city. If I zoom all the way out, I'd expect the smallest villages to disappear, then all villages, then all the way out I'd only have the largest city in my area. I tried to play a bit with using the population value for priority, but wasn't able to make it work.

  • When priority doesn't work, it is because there is another obstacle which is not letting show the label that you want. Solutions are custom because depends on all the data. If you want to provide a sample project, we can try to test it to find a solution. Commented Dec 19, 2019 at 3:38

1 Answer 1


Here's an approach using scale-based visibility. It's not exactly what you wanted, but it might be a usable workaround.

  1. Use rule-based labels. Make several rules, each with the same label text (eg, the city name).

  2. Filter each rule based on the population. Eg, if your city populations range from 1000 to 10 million, you might divide them into three different categories with these filters:

    • small cities (population less than 50 thousand): population <= 50000
    • medium cities (population between 50 thousand and 1 million): population > 50000 and population <= 1000000
    • large cities (population greater than 1 million): population > 1000000

    enter image description here

  3. Set the scale-based visibility for each rule, so that large cities are always shown, medium cities are only shown when slightly zoomed in, and small cities are only shown when zoomed in further.

Here's a completely different approach, using an expression to control label priority based on population. You may need to adjust the math depending on your population range.

enter image description here

The expected format of label priority is a decimal number between 0.0 and 10.0. So we just need an expression that converts the population values into numbers within that range. Here are a couple different options (again assuming a population range between 1 thousand and 10 million):

  1. Divide the "population" field by whatever number is needed so that the maximum population divide by that number is 10. Eg, if the maximum population is 10 million, divide the population field by one million.

    "population" / 1000000
  2. Use a conditional statement to convert manually-defined population ranges into categories. Using the same ranges from above, it would look like this:

        CASE WHEN population <= 50000 THEN 0
         WHEN population > 50000 AND population <= 1000000 THEN 5
         WHEN population > 1000000 THEN 10

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.