Sampling a raster layer
Data from a raster layer can be added to a points layer by querying the value of the layer in the coordinates of the points. This process is known as sampling, and this recipe explains how to perform it.
Getting ready
Open the dem.tif
raster layer and the dem_points.shp
vector layer:
How to do it…
In the Processing Toolbox menu, find the Add grid values to points algorithm and double-click on it to open it:
Select the DEM in the Grids field.
Select the point layer in the Points field.
Click on Run to run the algorithm.
A new vector layer will be created. This contains the same points as the input layer, but the attribute table will have an additional field with the name of the selected raster layer and the values corresponding to this layer in each point:
How it works…
The coordinates of the points are taken, and the value of the pixel in which the layer falls is added to the resulting points layer.
This method assumes that the value of a cell is constant in all the area covered...