I am trying to figure out how to buffer a vector shapefile with a variable distance (in QGIS). However, the variable distance needs to be dependent on the value of a raster (DEM) where that vector overlies the raster.

enter image description here

Put differently, the yellow buffer extends out to a distance that depends on the height of the DEM above some known height at the point where the purple line intersects the raster.

  • Are you buffering the yellow line or the purple line?
    – csk
    Apr 26, 2018 at 17:22
  • I would like to buffer the purple line. I have since used the raster calculator to modify the raster so that the raster values at the purple vector are exactly the distance I need to negative buffer the purple line. So all I need now is a way to negative buffer that purple line based on the raster value underneath it.
    – M.R
    Apr 26, 2018 at 17:25

1 Answer 1


This answer assumes the purple line is actually a line, not a polygon. If it's a polygon, run polygons to lines tool before step 1.

  1. Split the purple line into as many features as there are raster cells under it

    • densify by interval - This algorithm takes a polygon or line layer and generates a new one in which the geometries have a larger number of vertices than the original one. The geometries are densified by adding regularly placed extra nodes inside each segment so that the maximum distance between any two nodes does not exceed the specified distance.

    • use raster cell size as densify interval

    • explode lines - This algorithm takes a lines layer and creates a new one in which each line is replaced by a set of lines representing the segments in the original line. Each line in the resulting layer contains only a start and an end point, with no intermediate nodes between them.

  2. Add raster values to features (this is a SAGA tool)

  3. Variable distance buffer using raster values attribute for distance

    • in QGIS 3 the variable distance buffer tool has been merged into the buffer tool
  4. Dissolve buffer layer to obtain a single buffer feature

Note: Tool names are in bold. All the tools mentioned here are found in the Processing Toolbox.

If this is a process you want to run more than once, use the Graphical Modeler to create a repeatable process.

  • You are a GIS god among mortals. This is an awesome method. Thanks again.
    – M.R
    Apr 26, 2018 at 18:08

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.