This function updates a raster's extent by shrinking or expanding the x and y limits.

update_extent(x, x_shift, y_shift = x_shift)

Arguments

x

An extent object or an object from which there is an extent method (e.g., a raster).

x_shift

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).

y_shift

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).

Value

The function returns an updated extent object.

Author

Edward Lavender

Examples

# 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