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".

saQuist
  • 726
  • 1
  • 6
  • 21

2 Answers2

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

Matt
  • 16,843
  • 3
  • 21
  • 52
  • 1
    You were faster than me... – J.R Feb 03 '23 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 03 '23 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 03 '23 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

J.R
  • 16,090
  • 1
  • 19
  • 52