Extracting raster values based on vector layers
So far, we have covered operations to transform a vector layer to a raster and vice versa. The third operation involving vector layers and rasters, and the focus of this final section, is the extraction of raster values according to vector layers. We are often interested in reducing or summarizing raster data using point, line, or polygon features, which is when this operation comes in handy. For example, we may wish to calculate the elevation profile covered by a GPS track (raster-to-line extraction) or the average NDVI of a given forest (raster to polygon extraction). In this section, we will see two examples involving extraction by points and extraction by polygons.
Extracting by points
Extraction of raster values, according to a vector layer of any kind, can be done with the extract
function. The first two parameters of this function are as follows:
The raster whose values are to be extracted (
x
)The object (usually a vector layer) defining...