Learn R Programming

terra (version 1.7-3)

extend: Extend

Description

Enlarge the spatial extent of a SpatRaster. See crop if you (also) want to remove rows or columns.

You can also enlarge a SpatExtent with this method, or with algebraic notation (see examples)

Usage

# S4 method for SpatRaster
extend(x, y, snap="near", fill=NA, filename="", overwrite=FALSE, ...) 

# S4 method for SpatExtent extend(x, y)

Value

SpatRaster or SpatExtent

Arguments

x

SpatRaster or SpatExtent

y

If x is a SpatRaster, y should be a SpatExtent, or an object from which it can be extracted (such as SpatRaster and SpatVector objects). Alternatively, you can provide two positive integers indicating the number of rows and columns that need to be added at each side (or a single positive integer when the number of rows and columns is equal)

If x is a SpatExtent, y should be a numeric vector of 1, 2, or 4 elements

snap

character. One of "near", "in", or "out". Used to align y to the geometry of x

fill

numeric. The value used to for the new raster cells

filename

character. Output filename

overwrite

logical. If TRUE, filename is overwritten

...

additional arguments for writing files as in writeRaster

See Also

crop, merge, ext

Examples

Run this code
r <- rast(xmin=-150, xmax=-120, ymin=30, ymax=60, ncols=36, nrows=18)
values(r) <- 1:ncell(r)
e <- ext(-180, -100, 40, 70)
re <- extend(r, e)

# extend with a number of rows and columns (at each side)
re2 <- extend(r, c(2,10))

# SpatExtent
e <- ext(r)
e
extend(e, 10)
extend(e, c(10, -10, 0, 20))

Run the code above in your browser using DataLab