I have a line layer and want to add a series of 10 single sided buffers with increasing distance: 1, 2, 3... to 10. With geometry generator, I created this valid expression:


The output of this is an array of geometries. I can get the geometry with array_get( array,index), but like this it's only possible to render one geometry. However, I would like to display all 10 buffers, thus collect all ten geometries contained in the array. How is this possible with expressions?

2 Answers 2


How about collect_geometries()?

enter image description here

enter image description here


Geometry Generator is great for building new geometrie(s) for each initial feature. That is, a main limitation is the inability to produce new row of data.

While it is possible to create a complex multi-polygon geometry, as shown by @Kazuikito, it remains a single geometry with a single style.

If you need control over the generated data, say to label the buffers or use a different color per ring, you would have to prepare the buffers before styling them. This can still be an automatic solution if implemented as a virtual layer.

Go the the menu layer / add layer / add-edit virtual layer and enter the following query. Feel free to add any field you wish from your layer (here only the id is included)

WITH RECURSIVE generate_series(value) AS (
  SELECT 1 -- Smallest value
  SELECT value+1 FROM generate_series   -- "+1" is the step
   WHERE value+1 <= 10  -- "+1" is the step, 10 is the greatest value
SELECT s.value as bufferSize, SingleSidedBuffer(a.geometry, s.value,1) as geometry, a.id
FROM generate_series s, 
     myLineLayer a;

enter image description here

  • Perfect idea using the SingleSidedBuffer(). Do you know since when QGIS possess this function for Virtual Layers?
    – Taras
    Commented Nov 23, 2020 at 14:55
  • I was aware of the possibility to do it as a virtual layer, but felt more comfortable to it with geometry generator as I am more familiar with that. For this reason it's really great you added the virtual layer solution, I should really get more familiar with it. To this end, if you could please elaborate about the difference between the code in your answer and the one on your screenshot - there is missing the "as geometry, a.id" part. So with this part included, the query in the virtual layer does not work, whereas when I paste it as in your screenshot, it works.
    – Babel
    Commented Nov 23, 2020 at 14:55
  • 1
    @babel it should work if there is an id field in the source layer, you can really add any field you need from the source. The .. as geometry just gives a nice name to the geometry column, it would work with or without it
    – JGH
    Commented Nov 23, 2020 at 14:58
  • @Taras it is a spatialite function in this case. I don't know when it was introduced
    – JGH
    Commented Nov 23, 2020 at 15:01
  • @JGH, great - yes, adding an id field does the job!
    – Babel
    Commented Nov 23, 2020 at 15:06

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.