gdalwarp_grid: Warp a raster file aligning it on the grid of another file

View source: R/gdalwarp_grid.R

gdalwarp_gridR Documentation

Warp a raster file aligning it on the grid of another file

Description

The function applies gdalwarp to build rasters with the same projection, resolution and grid alignment of another raster. If not specified, the output format of each file is the same of the corresponding source file.

Usage

gdalwarp_grid(
  srcfiles,
  dstfiles,
  ref,
  of = NULL,
  r = NULL,
  dstnodata = NA,
  tmpdir = tempdir()
)

Arguments

srcfiles

A vector of input file paths (managed by GDAL).

dstfiles

A vector of input file paths.

ref

Path of the raster taken as reference.

of

The output format (use the short format name). Default is the format of every input filename.

r

Resampling_method ("near"|"bilinear"|"cubic"|"cubicspline"| "lanczos"|"average"|"mode"|"max"|"min"|"med"|"q1"|"q3").

dstnodata

(optional) Set nodata values for output bands (parameter passed to gdalUtil()).

tmpdir

(optional) Path where intermediate files (.prj) will be created. Default is a temporary directory.

Value

NULL (the function is called for its side effects)

Note

License: GPL 3.0

Author(s)

Luigi Ranghetti, phD (2019)

References

L. Ranghetti, M. Boschetti, F. Nutini, L. Busetto (2020). "sen2r": An R toolbox for automatically downloading and preprocessing Sentinel-2 satellite data. Computers & Geosciences, 139, 104473. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1016/j.cageo.2020.104473")}, URL: https://sen2r.ranghetti.info/.

Examples


# Define file names
ex_sel <- system.file(
  "extdata/out/S2A2A_20190723_022_Barbellino_BOA_10.tif",
  package = "sen2r"
)
ex_ref <- system.file(
  "extdata/out/S2A2A_20190723_022_Barbellino_SCL_10.tif",
  package = "sen2r"
)
ex_out <- tempfile(fileext = "_BOA_out.tif")

# Run function
sen2r:::gdalwarp_grid(ex_sel, ex_out, ref = ex_ref)

# Show output
oldpar <- par(mfrow = c(1,3), mar = rep(0,4))
image(stars::read_stars(ex_sel), rgb = 4:2, maxColorValue = 3500, useRaster = TRUE)
par(mar = rep(2/3,4))
image(stars::read_stars(ex_ref), useRaster = TRUE)
par(mar = rep(0,4))
image(stars::read_stars(ex_out), rgb = 4:2, maxColorValue = 3500, useRaster = TRUE)
par(oldpar)


sen2r documentation built on Nov. 10, 2023, 9:08 a.m.