5.14 Extent
= rast(system.file("raster/elev.tif", package = "spData"))
elev = rast(xmin = 0.9, xmax = 1.8, ymin = -0.45, ymax = 0.45,
clip resolution = 0.3, vals = rep(1, 9))
= FALSE] elev[clip, drop
## class : SpatRaster
## dimensions : 2, 1, 1 (nrow, ncol, nlyr)
## resolution : 0.5, 0.5 (x, y)
## extent : 1, 1.5, -0.5, 0.5 (xmin, xmax, ymin, ymax)
## coord. ref. : lon/lat WGS 84 (EPSG:4326)
## source(s) : memory
## name : elev
## min value : 18
## max value : 24
plot(elev)
Following code adds one row and two columns to each side of the raster while setting all new values to NA
= extend(elev, c(1, 2))
elev_2
plot(elev_2)
# PRODUCES ERROR: extends do not match
= elev + elev_2 elev_3
# correct implementation
= extend(elev, elev_2) elev_4