One of my more frequently visited posts is about how to extract data at point locations in QGIS (see here). In GRASS GIS this can be done with the ‘Sample raster maps at point location’ function. This uploads raster values of one or more raster layers at positions of vector points to user-defined columns in the attribute table.
Below a short explanation how to do this using the menu or command line. In the example I have a point vector layer ‘samples’ and the raster layers ‘precipitation’ and ‘temperature’.
1a) The data of the raster(s) will be written to user-defined columns. Any data in the columns will be overwritten. Often you will want to have the data of the raster layers written to new columns rather than updating existing ones. That means you’ll need to create one column per raster layer:
Open the screen using the menu: Database → Manage Databases → Add columns
Or use the command line: v.db.addcol
Select the point layer to upload the raster data and give the name and type of the columns you want to create. In the example above, I created two columns: PREC and TEMP, both with data type DOUBLE PRECISION. Next, click Run and you are done.
1b) Alternatively, you can open the point layer in the Layer Manager and open the attribute table (Figure 2).
In the Attribute Table Manager screen open the second tab ‘Manage table’ and add the columns in the ‘Column name’ field (Figure 3).
1c) Or, the easiest way, do it all at once on the command line:
v.db.addcol map=points@rwanda_work columns="PREC DOUBLE PRECISION, TEMP DOUBLE PRECISION"
2) To upload the raster values to the attribute table you can use the menu or command line:
Vector → Update point attributes from raster → Sample raster maps at point location
or type on the command line: v.what.rast
This will open the v.what.rast screen where you select the point layer, the name of the raster file to be queried and the column name to upload the raster values to (Figure 4)
Repeat this for all raster layers. Alternatively, use the command line:
v.what.rast vect=points rast=precipitation col=PREC
v.what.rast vect=points rast=temperature col=TEMP
Easy enough, ain’t it. Update: if you want to do something similar, but for lines instead of points, see the comments below.