terra (version 0.3-7)

warp: Transfer values of a SpatRaster to another one with a different geometry

Description

Warp transfers values between SpatRaster objects that do not align (have a different origin and/or coordinate reference system (crs)). This is also known as "resample" and/or "reproject". If the origin and crs are the same, you should consider using these other functions instead: aggregate, disaggregate, crop.

Usage

# S4 method for SpatRaster,SpatRaster
warp(x, y, method="bilinear", filename="", overwrite=FALSE, wopt=list(), ...)

Arguments

x

SpatRaster to be warped

y

SpatRaster that x should be warped to

method

character. Method used to compute values. "bilinear" for bilinear interpolation, or "ngb" for "nearest neighbor"

filename

character. Output filename. Optional

overwrite

logical. If TRUE, filename is overwritten

wopt

list. Options for writing files as in writeRaster

...

additional arguments. None implemented

Value

SpatRaster

See Also

aggregate, disaggregate, crop, project,

Examples

Run this code
# NOT RUN {
r <- rast(nrow=3, ncol=3, xmin=0, xmax=10, ymin=0, ymax=10)
values(r) <- 1:ncell(r)
s <- rast(nrow=25, ncol=30, xmin=1, xmax=11, ymin=-1, ymax=11)
x <- warp(r, s, method='bilinear')

par(mfrow=c(1,2))
plot(r)
plot(x)

# warp to different CRS
a <- rast(ncol=40, nrow=40, xmin=-110, xmax=-90, ymin=40, ymax=60, crs="+proj=longlat +datum=WGS84")
values(a) = 1:ncell(a)
b <- rast(ncol=94, nrow=124, xmin=-944881.473102882, xmax=935118.526897118, ymin=4664377.90135485, ymax=7144377.90135485, crs="+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84")
w <- warp(a, b)
# }

Run the code above in your browser using DataLab