16

The QGIS Geometry Generator seems like a nice way to keep data intact while allowing for some creative visualisations.

I have a layer of tesselating polygons that I would like to style as a continuous surface without internal borders.

To dissolve a number of polygons in Spatialite I would use the UNION function, but Union in the Geometry Generator doesn't give a result, ie:

 union($geometry, $geometry)

So is it possible to use the Geometry Generator to show a polygon layer as dissolved, and if so, how?

Taras
  • 32,823
  • 4
  • 66
  • 137
hexamon
  • 2,646
  • 1
  • 16
  • 26

2 Answers2

21

You can now do this with the geometry generator in QGIS 2.99/3.0 by using buffer(collect($geometry), 0) in the expression builder.

The new collect() aggregate function collects all the feature geometries into a multipolygon; buffer() converts it into a single polygon to be styled as such.

EDIT: As indicated by the comment below, the above method does run into limitations when using opacity (as if you still have 3 separate rings in your "merged" polygon it will render 3 times).

In QGIS 3.18 however this is completely solved by the Merged Features rendering option

Taras
  • 32,823
  • 4
  • 66
  • 137
she_weeds
  • 12,488
  • 1
  • 28
  • 58
  • 1
    Is there a way to do this result without collect but as a merge? If you test this on a polygon with 2 features and a semi-transparent simple fill, you'll notice the expression is carried out twice and the fill will be twice as opaque as you designatied. – James B Sep 10 '19 at 15:52
  • 1
    Realised this is possible with the inverted polygon style thus requiring no code =) – James B Sep 12 '19 at 08:19
14

I've tried using the Geometry Generator with no success, and decided on a "Virtual layer" and a SQL query

SELECT st_union(geometry)
FROM layer_name

You need to replace "layer_name" with your layer name.

The resulting virtual layer is based on the source layer and will not create any new data.

It's not the geometry generator style, but it should fix your problem.

Taras
  • 32,823
  • 4
  • 66
  • 137
Klas Karlsson
  • 906
  • 6
  • 13