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?
2 Answers
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.
-
I think it should be
select buffer(geometry,500) as geometry from myline
. And nice thing that virtual layers now get updated immediately. Commented Jan 18, 2019 at 21:34 -
-
I will try this solution ! Does i need a single quote or double quote for the name of myline layer?– ArthurCommented Jan 21, 2019 at 9:22
-
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.
-
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– ArthurCommented Jan 21, 2019 at 9:22
-
1So 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.RCommented Jan 21, 2019 at 10:01