projecExtent
returns a RasterLayer with a projected extent, but without any values. This RasterLayer can then
be used as 'to'
RasterLayer in projectRaster
. projectRaster
computes values for the cells of the new RasterLayer.projectRaster(from, to, method="ngb", filename="", ...)
projectExtent(object, projs)
projInfo('proj')
, projInfo('ellps')
, and projInfo('datum')
for options for valid PROJ.4 strings.
You can consult this page: ?CRS
The following additional arguments can be passed, to replace default values for this function
overwrite
Logical. If TRUE
, "filename" will be overwritten if it exists
format
Character. Output file type. See writeRaster
datatype
Character. Output data type. See dataType
progress
Character. Valid values are "text", "tcltk", "windows" (on that platform only) and ""
}CRS-class
, projInfo
# create a new (not projected) RasterLayer with cellnumbers as values
r <- raster(xmn=-110, xmx=-90, ymn=40, ymx=60, ncols=40, nrows=40)
r <- setValues(r, 1:ncell(r))
# proj.4 projection description
newproj <- "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +ellps=WGS84"
# create a new RasterLayer with a projected extent (no values are transferred)
pr <- projectExtent(r, newproj)
# Adjust the cell size
res(pr) <- 100000
# project the values of RasterLayer 'r' to the new RasterLayer 'projras'
pr <- projectRaster(r, pr)
# inverse projection, back to the properties of 'r'
inv <- projectRaster(pr, r)
## using a higher resolution and bilinear interpolation
# res(pr) <- 10000
# pr <- projectRaster(r, pr, method='bilinear')
# inv <- projectRaster(pr, r, method='bilinear')
# dif <- r - inv
# plot(dif)
Run the code above in your browser using DataLab