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
.
# S4 method for SpatRaster,SpatRaster
warp(x, y, method="bilinear", filename="", overwrite=FALSE, wopt=list(), ...)
SpatRaster to be warped
SpatRaster that x
should be warped to
character. Method used to compute values. "bilinear"
for bilinear interpolation, or "ngb"
for "nearest neighbor"
character. Output filename. Optional
logical. If TRUE
, filename
is overwritten
list. Options for writing files as in writeRaster
Additional arguments. None implemented
SpatRaster
# 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