3

I'm new to QGIS.

I'm currently using the new version 3.20.0 Odense and I have some troubles setting up the rule-based labelling for a layer.

Essentially, what I need is to automatically swap labels base on active layers; I don't even know if it's possible but I have tried several conditional statements in conjunction with is_layer_visible and everything seems to be pointless...

I have my map set (Positron - retina) and three other layers, two of them plotting different entities and the third one is a summary SVG icon displayed on each of the five continents.

This last layer is the one for which I would like labels to become visible based on which of the other two layers I selected from the Layers Panel on the right.

2
  • You want to label layer C based on whether layer A or layer B is activated, is this correct? What should happen when both layer A and B are visible? Have you considered duplicating layer C, setting the correct labels and turning it on/off along with the corresponding layer A/B?
    – Erik
    Sep 30, 2021 at 7:48
  • Yes, I have considered that option (it's actually what I'm doing right now); however, I just wanted to have some more "interactive" features on my map... with that said to answer your first question when both layers are not visible labels should disappear too.
    – Matteo
    Sep 30, 2021 at 9:57

2 Answers 2

3

Set a rule based label with Filter is_layer_visible ('layer1') an the label settings for layer 1 (see screenshot 1). Copy and paste this rule and adapt is (see screenshot 2). When you now toggle visibility of layer1 and layer2, the label on layer3 will adapt and show the layer for the layer(s) that is (are) visible.

Screenshot 1: enter image description here

Screenshot 2: enter image description here

2
  • Thanks a lot, unfortunately, for some reasons both labels are printed on map... even when I deselect both layers. I honestly don't know why, it could be because I'm importing the labels form a .csv?
    – Matteo
    Sep 30, 2021 at 11:03
  • I'm not really sure what you meant with "iport labels form a csv". Easiest to understand your very problem would be sharing your project+data (at least a sample or dummy data). Is that possible?
    – Babel
    Sep 30, 2021 at 12:37
-1

I had to submit my project so, I opted for the easiest solution: two label layers... however, now that it's all done I'm more than happy to learn how to do a proper conditional labelling.

I followed the steps @Babel indicated in his answer and what I need is basically for the layer called conditional labelling (when is selected) to show different labels based on the active layers, namely integrated_data-GA100Kexcluded and integrated_data-GA100Kincluded.

Below some screenshots, I hope they can help. Let me know.
enter image description here

enter image description here

enter image description here

1
  • 2
    As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Oct 5, 2021 at 7:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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