[GIS] Extracting raster values with polylines in QGIS

interpolationlineqgisraster

I have a polyline shapefile that represent a road an a raster grid with slope values.
Is it possible to interpolate the shape file and the grid to have the average slope of the road?
I know that I can interpolate grid with points and polygons. But with lines?

Best Answer

This is a bit of a late answer, but I thought it was worth contributing.

As a polyline is just a series of points you should be able to obtain the Mean value you want by converting the Polyline nodes into points by going Vector > Geometry Tools > Extract Nodes...

You can then extract the underlying Raster values for each of these points by using the Point Sampling Tool plugin. This plugin will create a new Points shapefile with the underlying raster grid cell's value within its Attribute table. See here: http://infogeoblog.wordpress.com/2013/06/23/raster-data-extraction/

Note that the Point Sampling Plugin can be quite fussy with the CRS and can result in a NULL output. I managed to get it to work by ensuring that the layers and project CRS were all the same.

If you want a higher sample rate, then I suppose you could densify the number of nodes by using Vector > Geometry Tools > Densify Geometries... prior to extracting them.

You can then use Vector > Analysis Tools > Basic Statistics... to attain the Mean Slope value.