
Shift
shift.RdShift a SpatRaster, SpatVector or SpatExtent to another location.
Usage
# S4 method for class 'SpatRaster'
shift(x, dx=0, dy=0, filename="", to, ...)
# S4 method for class 'SpatVector'
shift(x, dx=0, dy=0, to)
# S4 method for class 'SpatExtent'
shift(x, dx=0, dy=0, to)Arguments
- x
SpatRaster, SpatVector or SpatExtent
- dx
numeric. The shift in horizontal direction
- dy
numeric. The shift in vertical direction
- to
SpatExtent, or an object from which an extent can be extracted (see
ext); or two coordinates (x, y) for the new center ofx. One of the two coordinates may beNAto shift only in the other direction. Iftois used,dxanddycannot be used- filename
character. Output filename
- ...
additional arguments for writing files as in
writeRaster
Examples
r <- rast(xmin=0, xmax=1, ymin=0, ymax=1)
r <- shift(r, dx=1, dy=-1)
e <- ext(r)
shift(e, 5, 5)
#> SpatExtent : 6, 7, 4, 5 (xmin, xmax, ymin, ymax)
# center on another object or on coordinates
e2 <- ext(10, 12, 4, 8)
shift(e, to=e2)
#> SpatExtent : 10.5, 11.5, 5.5, 6.5 (xmin, xmax, ymin, ymax)
shift(e, to=c(11, 6))
#> SpatExtent : 10.5, 11.5, 5.5, 6.5 (xmin, xmax, ymin, ymax)
shift(e, to=c(11, NA))
#> SpatExtent : 10.5, 11.5, -1, 3.8163916471489756e-17 (xmin, xmax, ymin, ymax)