Extend
extend.RdExtend returns an Raster* object with a larger spatial extent. The output Raster object has the outer minimum and maximum coordinates of the input Raster and Extent arguments. Thus, all of the cells of the original raster are included. See crop if you (also) want to remove rows or columns.
There is also an extend method for Extent objects to enlarge (or reduce) an Extent. You can also use algebraic notation to do that (see examples).
This function has replaced function "expand" (to avoid a name conflict with the Matrix package).
Usage
# S4 method for class 'Raster'
extend(x, y, value=NA, snap="near", filename='', ...)
# S4 method for class 'Extent'
extend(x, y, ...)Arguments
- x
Raster or Extent object
- y
If
xis a Raster object,yshould be an Extent object, or any object that is or has an Extent object, or an object from which it can be extracted (such as sp objects). Alternatively, you can provide a numeric vector of length 2 indicating the number of rows and columns that need to be added (or a single number when the number of rows and columns is equal)If
xis an Extent object,yshould be a numeric vector of 1, 2, or 4 elements- value
value to assign to new cells
- snap
Character. One of "near", "in", or "out", to determine in which direction the extent should be aligned. To the nearest border, inwards or outwards
- filename
Character (optional)
- ...
Additional arguments as for
writeRaster
Examples
r <- raster(xmn=-150, xmx=-120, ymx=60, ymn=30, ncol=36, nrow=18)
values(r) <- 1:ncell(r)
e <- extent(-180, 0, 0, 90)
re <- extend(r, e)
# extend with a number of rows and columns (at each side)
re2 <- extend(r, c(2,10))
# Extent object
e <- extent(r)
e
#> class : Extent
#> xmin : -150
#> xmax : -120
#> ymin : 30
#> ymax : 60
extend(e, 10)
#> class : Extent
#> xmin : -160
#> xmax : -110
#> ymin : 20
#> ymax : 70
extend(e, 10, -10, 0, 20)
#> class : Extent
#> xmin : -160
#> xmax : -110
#> ymin : 20
#> ymax : 70
e + 10
#> class : Extent
#> xmin : -155
#> xmax : -115
#> ymin : 25
#> ymax : 65
e * 2
#> class : Extent
#> xmin : -165
#> xmax : -105
#> ymin : 15
#> ymax : 75