Quick guide to geometry generator symbol layers

Geometry generator symbol layers are a feature that has been added in QGIS 2.14. They allow using the expression engine to modify geometries or even create new geometries while rendering.

Geometry generator symbol layers make it possible to use expression syntax to generate a geometry on the fly during the rendering process. The resulting geometry does not have to match with the original geometry type and we can add several differently modified symbol layers on top of each other.

The latest version of the QGIS user manual provides some example expressions, which served as a basis for the following examples:

Rendering the centroid of a feature

To add a geometry layer representing feature centroids, we need to set the geometry type to Point / Multipoint and enter the following expression:

centroid( $geometry )

It is worth noting that the correct geometry type has to be set manually. If a wrong type is set, the symbol layer can not be rendered.

Drawing buffers around features

Buffers are an example of a polygon geometry generator layer. The second parameter of the buffer function defines if the buffer is generated outside (for positive values) or inside (for negative values) of the feature. The value has to be provided in the layer’s CRS units, in this case, that means an inner buffer of 0.005 degrees:

buffer( $geometry, -0.005 )

Creating a line between features in different layers

The following expression creates lines from all district centroids (as shown in the first example) and a feature from the Citybike layer where the STATION attribute value is ‘Millennium Tower’:

make_line( 
  centroid( $geometry ),
  geometry( get_feature( 'Citybike', 'STATION', 'Millennium Tower' ) ) 
)

More advanced examples

Using these basic examples as a starting point, geometry generators open a wide field of advanced symbology options. For example, this sector light style presented on GIS.Stackexchange or my recently introduced conveyor belt flow style:

12 comments
  1. Auslander said:

    This is really neat. Is there a way to do this with classified features? Often I’ll apply some random color ramp I’ve made over a bunch of countries, and then would like to apply this sort of method in a way that inherits the categorized color of its parent feature.

    For example, desired behavior would be – for each feature, give it a buffered polygon of say 5mm that is 20% lighter than the feature color.

    The “draw effects” functionality – as awesome as it is – also lacks this ability. Ideas?

    • If the colors are stored in a field, it should be pretty straightforward to do; otherwise, maybe a custom function is needed, and I’m quite sure it should be doable without much effort. However, this would be a nice question on GIS Stack Exchange. :)

      • Auslander said:

        Actually, I just bought Ms. Graser’s excellent book QGIS Map Design, and this exact thing is covered on pages 26-28. I didn’t have the book in hand yet when I originally posted the question. :)

  2. Matthias said:

    Hey Anita, it’s an awesome post. I can’t find the Geometry Generator in QGIS 2.8. Is there an extension necessary? What is Geometry Generator called in the german version?

    • You need QGIS 2.14 or higher to use geometry generators.

  3. Tobias said:

    (Old post, i know. )
    I have been searching for a way to do wavy lines in QGIS. Not using SVG or using a “s” in point fill, as I find it hard to get it to look good.
    Do you know of a way to use geometry generator (or something else) to get wavy lines?

    • I think there was a thread on this issue on gis.stackexchange.com a while back but cannot look it up right now.

  4. Koen Vereycken said:

    Dear,
    Your website is really inspiring for getting the most out of QGIS. Since I discovered postgis, a new world opened for me.
    I just had a question about a simple buffer geometry generator.
    Would it be possible to dissolve single buffered points, so no overlap between different points is being made on the map?
    Thanks in advance,
    Koen