QGIS has a powerful expression machine that can be used (between other things) to create new geometries, based on existing layers. Basically, there are two options: Geometry generator (introduced in QGIS 2.14) and Geometry by expression (introduced in QGIS 3.0). What is the difference between these two options?

Remark: this question is a case of

you’d like to document [a question] in public so others (including yourself) can find it later

As I often answer questions that involve creating geometries using expressions, I always have to repeat some basics. I think it's better to have the relevant information in a separate post that can be referred to keep answers shorter. Feel free to add further answers with additional information.

1 Answer 1


Quick overview how to create new geometries using QGIS expressions with either Geometry generator or Geometry by expression:

Geometry generator: Open Layer Styling panel / add additional symbol layer (green +) / Symbol layer type: Geometry generator / set appropriate Geometry type (point/line/polygon) / add your expression

Geometry by expression: Menu Processing / Toolbox / Geometry by expression / choose input layer / set appropriate Output geometry type/ add your expression

Overview Differences: Table Geometry generator vs. Geometry by expression - highlighted in green which option is better fit for the corresponding task: enter image description here

In more details: You can use the same expressions in both ways, depending on what you use it for.

Geometry generator: This is useful for creating dynamic geometries on a layer for visualization purposes only. Disadvantage: They are symbologies, thus you can't use it for further geoprocessing.

Advantage: However, they are great because you can see in realtime how the geometries change when you change the expression. You can try this with a simple example: use buffer ($geometry, 1) and add zeros to the number 1 to see the buffer successively increase with each digit you add. Like this, you can control the appearance of the geometry you create in a very intuitive way and learn how different settings affect the geometry.

How to do it:

  1. Open Layer Styling panel and add an additional symbol layer by hitting the green plus symbol: +.
  2. Than set the Symbol layer type to Geometry generator.
  3. Select a Geometry type: it is the kind of geoemtry you want to create, not the one of the geometry the expression is based on. A simple example: if you want to create a buffer, always select Polygon / MultiPolygon, irrespective if you buffer a point, line or polygon layer. If you create a centroid, however, always set Geometry type to Point / MultiPoint.
  4. Add the expression. You might use the epsilon (ε) button to open the powerful Expression string builder: see details about it in the documentation

Screenshot: how to use Geometry generator. Starting point is a line-layer (black line). Add a symbol layer in the layer styling panel and on this symbol layer create a buffer (transparent orange), here with the expression buffer ($geometry, 100). Change the shape of the black line or the buffer-distance from 100 to any other value to see how the orange buffer changes: enter image description here

Geometry by expression: This is useful if you need the created geometries for further processing. It will create a new layer containing the generated geometries and will thus be permanent (if you save the layer). Once executed, you can't however adapt the settings any more (as in the more flexible case of geometry generator, where you can always change settings, however the geometries can not be used for further processing).

How to do it:

  1. Go to Menu Processing / Toolbox / Geometry by expression
  2. Choose the input layer: the layer the expression is apllied to
  3. As Output geometry type, set the kind of geoemtry you want to create (see above for details)
  4. In the field Geometry expression, introduce the expression you want to use for generating geometries. You can use Expression string builder (ε): see details above.

Be aware that some functions available in geometry generator are not properly supported when using Geometry by expression, e.g. the variable refering to the current layer @layer or aggregate functions.

Screenshot: using Geometry by expression, creating the centroid of the line layer. It will be generated as a new point layer: enter image description here


  • This is a really great answer, and I very much appreciate being able to refer to this post. I was able to create geometries via the Geometry by Expression, but for some reason it didn't work on all the records I expected. And I can't get Geometry Generator within a symbol class working the way I want (generating a line between two points, each in a different layer). Toward that end, you mention "some functions available in geometry generator are not properly supported when using Geometry by expression" - can you expand on that?
    – Mike D
    Commented Jan 10 at 19:03
  • EDIT: Figured out why some records failed on geometry generation - just some bad IDs in my source. But after fixing that, I still couldn't create geometries for a virtual layer. I had to export the virtual layer to a geopackage and then apply the geometry generation style in order to get things to work. Does it make sense for geometry from a virtual layer to be limited in this use?
    – Mike D
    Commented Jan 10 at 19:37
  • 1
    On virtual layers, geometry Generator should work normally. With geometry by expression, especially aggregate functions can be problematic
    – Babel
    Commented Jan 10 at 19:53

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.