update_extent(x, x_shift, y_shift = x_shift)
An extent
object or an object from which there is an extent
method (e.g., a raster
).
A number that defines the change in the x limits. Positive numbers increase the extent (i.e., the lower limit is reduced and the upper limit is increased) while negative numbers reduce extent (i.e., the lower limit is increased and the upper limit is decreased).
A number that defines the change in the y limits. By default, this equals x_shift
(i.e., the extent
is changed uniformly in all directions).
The function returns an updated extent
object.
# Define example raster
r <- raster::raster(
nrows = 3, ncols = 3,
resolution = c(5, 5),
ext = raster::extent(0, 15, 0, 15)
)
# Increase raster extent by 5 units in every direction
update_extent(r, 5)
#> class : Extent
#> xmin : -5
#> xmax : 20
#> ymin : -5
#> ymax : 20
# Decrease raster extent by 5 units in every direction
update_extent(r, -5)
#> class : Extent
#> xmin : 5
#> xmax : 10
#> ymin : 5
#> ymax : 10
# Increase x and y extent parameters differently
update_extent(r, 5, 10)
#> class : Extent
#> xmin : -5
#> xmax : 20
#> ymin : -10
#> ymax : 25