2

I have recently started working with QGIS. Quite new to this software. Anyway, my first task is to create contours from shapefiles using buffers, unions and dissolve functions. This shapefiles are jointed to CSV files where the contour size will be based on.

Problem is, the values in my CSV will need to be changed from time to time, so does the contours created. Is there anyway I can automatically update my contours everytime my CSV file values change?

1 Answer 1

2

You can do this if you create the buffers either with Virtual layer or Geometry generator.

  1. Virtual layer: does create actual geometries. Use this query:

    select st_buffer (p.geometry, b.size)
    from point as p, buffersize as b
    where p.id = b.id
    
    • Replace point with the name of the layer containing the geometries that you want to buffer.
    • Replace buffersize with the name of the csv layer containing the attribute field size that defines the buffer distance.
    • Both layers should have a field called id that joins them.

For multiple buffer distances, you can create multiple buffers, combining the repeated query with union:

SELECT st_buffer (p.geometry, b.size) as geom 
   from point as p, buffersize as b
   where p.id = b.id
union
SELECT st_buffer (p.geometry, b.size2) as geom 
   from point as p, buffersize as b
   where p.id = b.id
union
SELECT st_buffer (p.geometry, b.size3) as geom 
   from point as p, buffersize as b
   where p.id = b.id

Or use st_collect to combine two buffers, but it will be a multipart feature:

    select  st_collect (st_buffer (p.geometry, b.size), st_buffer (p.geometry, b.size2))...
  1. Geometry generator: does only create the buffers as style, not actual geometries - see here for details. On the layer containing the geometries you want to buffer, create a symbol layer of the type Geometry generator and use the expression buffer ($geometry, size). Replace size with the field from your CSV.
2
  • Can I use the virtual layer if I have multiple points on the map, with multiple buffer distance for each point as well?
    – zaido141
    Jan 4, 2022 at 10:03
  • Use st_collect, see updated answer
    – Babel
    Jan 4, 2022 at 10:23

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.