Description Usage Arguments Details Value Author(s) References Examples
This function allows single scenes to be warped to a given projection. No mosaicking is performed. The function can handle multiple NoData values and can output an alpha layer, which a warped layer containing the NoData values only.
1 2 |
x |
Character. The filename of the layer to be warped. |
t_srs |
character. proj4 expression of the output ( |
nodata |
numeric. Value that should not get interpolated in the
resampling. Can take multiple values (i.e.: |
filename |
character. filename of the output file, with full path. |
res |
numeric. output resolution. |
method |
character. resampling method. See http://www.gdal.org/gdalwarp.html |
alpha |
Logical. Should an alpha layer be created. Only makes sense in case multiple NoData values are provided. |
run |
logical. should the warping be executed. If set to false, a gdalwarp command string is generated, but not executed. |
... |
Character. Extra switches passed to |
Requires gdal to be installed on the system, and the the gdal binary folder
should be added to the system path. On windows systems, gdal can be installed
via FWTools, OSGeo4W or QGIS. Function behavior is quite different depending on
whether single and multiple NoData are provided. gdalwarp
, which is
called via a system command does not support multiple NoData values, as a
consequence the present function first aggregates all values provided in a
single value and does the warping in a second stage.
A character, or list of characters, the gdalwarp command(s). If you
inted to copy/past it in a terminal, you can use print()
, with
quote=FALSE
.
Loic Dutrieux
http://www.gdal.org/gdalwarp.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | ## Not run:
pr <- getPR('Belize')
pr <- pr$PR[1]
dir <- tempdir()
downloadPR(pr, year=2000, dir=dir)
unpackVCF(pr=pr, year=2000, searchDir=dir, dir=sprintf('%s/%s',dir,'extract/'))
x <- list.files(sprintf('%s/%s',dir,'extract/'), full.names=TRUE)
filename <- sprintf('%s.tif', rasterTmpFile())
warp(x=x, t_srs='+proj=laea +lat_0=-10 +lon_0=-70 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs', nodata = c(200, 210, 211, 220), filename=filename)
a <- raster(filename)
# This function is intended to be applied to several scenes, as a way to prepare them before mosaicking
# The example below performs warping over three files and subsequently mosaic them
pr <- getPR('Belize')
dir <- tempdir()
downloadPR(pr, year=2000, dir=dir)
unpackVCF(pr=pr, year=2000, searchDir=dir, dir=sprintf('%s/%s',dir,'extract/'))
x <- list.files(sprintf('%s/%s',dir,'extract/'), full.names=TRUE)
wrap <- function(x) {
filename <- filename <- sprintf('%s_warp.tif', x)
w <- warp(x=x, t_srs='+proj=laea +lat_0=-10 +lon_0=-70 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs', nodata = c(200, 210, 211, 220), filename=filename)
return(w)
}
mclapply(X=x, FUN=wrap, mc.cores=3)
x2 <- list.files(sprintf('%s/%s',dir,'extract/'), pattern=glob2rx('*warp*'), full.names=TRUE)
x3 <- lapply(X=x2, FUN=raster)
x3$fun <- mean
x3$filename <- sprintf('%s/%s',dir,'extract/mosaic_belize.tif')
do.call(raster::mosaic, x3)
plot(r <- raster(x3$filename))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.