5

I am creating some lines, and I would like to add a 500m buffer around thoses lines. But i need this buffer to automaticaly change if i modify my line around. Is there any solution to this?

1
  • What do you mean by automatically change? Do you mean you are manually modifying the line your buffer is based off of? Commented Jan 18, 2019 at 16:24

2 Answers 2

10

You can create a virtual layer that is linked to your source layer. It has the advantage of creating a new in-memory layer that can easily be turned on/off.

Go to menu layer / add layer / add - edit virtual layer and use the formula

select st_buffer(geometry,500)
from myline;

The buffer distance is in the projection unit, so in meters or degrees.

4
  • I think it should be select buffer(geometry,500) as geometry from myline. And nice thing that virtual layers now get updated immediately.
    – MrXsquared
    Commented Jan 18, 2019 at 21:34
  • @MrXsquared Virtual Layers are truly awesome! Both buffer syntax are valid, and the alias is not needed (unless you want to run other queries on it). One may have to pan/refresh the map to see the new shape in the virtual layer.
    – JGH
    Commented Jan 18, 2019 at 22:01
  • I will try this solution ! Does i need a single quote or double quote for the name of myline layer?
    – Arthur
    Commented Jan 21, 2019 at 9:22
  • @Arthur either should work
    – JGH
    Commented Jan 21, 2019 at 12:08
5

One easy solution is to use the geometry generator, the drawback with this solution is that the buffer exists only on the display (not a layer you can reuse) and only in the document where it's configured. Also if you have many lines it may slow down rendering.

If you choose to go this way just go to the symbology tab of the line layer, click the plus to add a symbol layer and choose the Geometry generator type with Polygon/Multipolygon geometry then just type buffer( $geometry,500) as function (this only work if you are working in a CRS in meter, if not you will need to add some reprojection to the function). You could then symbolize the buffer to your liking.

As the buffer is dynamically created on the line geometry it will reflect any change to the line.

enter image description here

2
  • Thanks, this is a very easy solution but as you said only for display. I would need the buffer to calculate population within each buffer, therefore need a vector buffer
    – Arthur
    Commented Jan 21, 2019 at 9:22
  • 1
    So the answer with virtual layer is the way to go,(it's also very simple and you get a layer you could use for analysis and that's simpler to symbolise independently)
    – J.R
    Commented Jan 21, 2019 at 10:01

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.