6.1 Raster cropping/masking
One (very) common problem: the extent of input raster is larger than the area of interest.
Solution: Cropping and masking!
# a raster: SpatRaster
= terra::rast(system.file("raster/srtm.tif", package = "spDataLarge"))
srtm = sf::read_sf(system.file("vector/zion.gpkg", package = "spDataLarge"))
zion # same CRS for both of this object
= st_transform(zion, crs(srtm))
zion # always do a quick viz
plot(srtm, col = grDevices::terrain.colors(50))
plot(zion$geom, add = TRUE)