3

I have one layer with macro-regions and micro-regions attributes and I want to do two symbologies classification for each one. Is that possible?

I want to have this exact symbology, the macro-regions with bigger stroke width and the other one normal, without having to duplicate the layers or create new features in the origin layer.

enter image description here

enter image description here

The attribute table looks like this. The macro-regions are represented to the field "batalhao".

6
  • Can you add a screenshot showing the attribute table
    – Bera
    Feb 2, 2023 at 18:26
  • 1
    Here is a solution using a virtual layer.
    – JGH
    Feb 2, 2023 at 19:08
  • can't you just make a rule-based symbology with different widths ?
    – Kalak
    Feb 3, 2023 at 8:50
  • @BERA I added the attribute table in the post Feb 3, 2023 at 13:19
  • @LouisCottereau I tried the merged features symbology with the sub render rule based but it simply doesn't work. Feb 3, 2023 at 13:21

2 Answers 2

6

You can add an extra symbol layer of Geometry Generator type

enter image description here

Expression
case
    when
        $id = array_max (   
            array_agg(
                $id,
                group_by:="batalhao"
            )
        )
    then    
        buffer(
            collect(
                $geometry,
                group_by:="batalhao"
            ),
            0   -- the 0 distance buffer is to "dissolve" the collected geometries
        )
end

Thanks to the very helpful input from @JGH, the expression could be optimised (using this solution). The case statement ensures that the collection and buffering only occurs once per macroregion, rather than once for every microregion.

Result

enter image description here

Notes

The symbol layer disappears when the canvas is panned or zoomed so that the microregion with the maximum id (per macroregion) is completely off the screen.

enter image description here

Whereas array_max places the macroregion boundary on top of the microregions, using array_min in the when clause of the case statement places the macroregion boundary beneath the microregions. Except for the boundary of the microregion with the minimum id. This is visible when using a light colour for the Geometry Generator stroke.

enter image description here

3
  • 1
    You were faster than me...
    – J.R
    Feb 3, 2023 at 13:50
  • 1
    It is slow because the aggregation is computed for every sub-region and displayed stacked on top of each others. To speed it up, one can flag 1 sub-region per higher-region, then conditionally apply the aggregation expression only on the flagged records.
    – JGH
    Feb 3, 2023 at 14:12
  • Thank you, @JGH. I have adapted my answer according to your suggestion (which reminded me of a question of my own from about a year ago year that Babel answered). It works like a charm now.
    – Matt
    Feb 3, 2023 at 14:41
1

You may just add a second symbol layer on top with a geometry generator expression like : buffer(collect($geometry, "batalhao"),0) (note that will slow down rendering)

enter image description here

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.