Sampling raster values into attribute table of polyline layer

averageqgisrastervector

I have several raster layers and one vector polyline layer. I'd like to sample the rasters into the attribute table of the vector layer. Because the lines span multiple raster cells, this can be done by averaging raster values along line segments.

Is there a way to neatly do this?

Right now I'm using QGIS.

Best Answer

  1. Densify by interval to add more vertices to your lines (optional)
  2. Drape to extract the raster values to each lines vertices z value
  3. Extract z values to add these as an attribute, with Summaries to calculate = mean
  4. Repeat for each raster. For example manually or using pyqgis

enter image description here