4

All countries have their colors according to different values. And I need to additionally mark with a stroke those countries that are in the YES category. If there are few countries next to each other, the stroke should be one for them and not for each one separately. How can this be done within a single layer? Is this even possible?

I tried to do it as a duplicate of the layer, with the symbology of the category YES. But it turns out that each country has its own stroke (picture).

The main idea in implementing this is the ability to show / hide the YES category in one click.

enter image description here

Taras
  • 32,823
  • 4
  • 66
  • 137
Jonny
  • 105
  • 7
  • Here is an existing solution that uses a virtual layer. While similar to the geometry generator answer, the main difference is that the union of the polygons is done once when using the virtual layer, while it is recomputed for every input polygon when using the geometry generator (that is, in your example, there would be 3 identical, overlapping, 'yes' polygons) – JGH Sep 07 '21 at 11:46

1 Answers1

7

Use Categorized renderer, make the settings based on value, than change to Rule-based renderer and add another rule for category.

enter image description here

To get a border around the category='yes' countries, but not between them, set the last style at the bottom to Geoemtry generator and use this expression:

buffer (
    collect (
        $geometry, 
        filter:=category = 'yes'
    ),
    0
)

enter image description here

Babel
  • 71,072
  • 14
  • 78
  • 208
  • Almost what I need, but do not need a border between these countries that fall into the category of YES. That is, there should be one stroke for all these countries, without between them. And when I turn off the YES category, the countries hide at all. Is it possible to make the stroke disappear and the countries remain in place with their colors? – Jonny Sep 07 '21 at 07:36
  • 1
    See updated answer - hope that solves the problem? – Babel Sep 07 '21 at 08:12
  • You are incredible! EVERYTHING WORKS! THANK YOU! May God protect you! – Jonny Sep 07 '21 at 09:52
  • is it possible i do the same thing in another project file - and nothing. By the time I choose a geometry generator - everything works, the YES category gets its new style. After I select the geometry generator and insert the code (yes, I change the names of the categories, etc.) - everything disappears. Isn't this due to the fact that I attached another data table to the layer in the new project file? – Jonny Sep 07 '21 at 11:48
  • Sorry, I don't understand what you mean. Can you post a screenshot of the problem or share your project? As comments are not apt for longer discussions, you might open a new question for this problem. – Babel Sep 08 '21 at 07:48
  • I cannot share the project under any circumstances. I can share a screenshot. My problem seems to be solved, and it was not quite a problem) The fact is that in my project there are about 20,000 polygons, of which about 5,000 were in the YES category. And when I did, as you wrote, all the polygons disappeared from the screen - only the white screen. I thought that this method that you wrote in my project does not work. part 1 – Jonny Sep 10 '21 at 10:31
  • But it turned out that it took time to render. I did a smaller project several times and tried the same thing - and some time after inserting the formula into the geometry generator everything rendered up (it took a few minutes). In the screenshots you can see the polygons from the YES category, then the white screen after the geometry generator, and then after a few minutes everything rendered up. https://i.ibb.co/F5grmv8/111.png Any way, thank you. This is a great solution that suits me. thanks part2 – Jonny Sep 10 '21 at 10:32