warp {gdalraster}R Documentation

Raster reprojection and mosaicing

Description

warp() is a wrapper of the gdalwarp command-line utility for raster mosaicing, reprojection and warping (see https://gdal.org/programs/gdalwarp.html). The function can reproject to any supported spatial reference system (SRS). It can also be used to crop, resample, and optionally write output to a different raster format. See Details for a list of commonly used processing options that can be passed as arguments to warp().

Usage

warp(src_files, dst_filename, t_srs, cl_arg = NULL, quiet = FALSE)

Arguments

src_files

Character vector of source file(s) to be reprojected.

dst_filename

Character string. Filename of the output raster.

t_srs

Character string. Target spatial reference system. Usually an EPSG code ("EPSG:#####") or a well known text (WKT) SRS definition. If empty string "", the spatial reference of src_files[1] will be used (see Note).

cl_arg

Optional character vector of command-line arguments to gdalwarp in addition to -t_srs (see Details).

quiet

Logical scalar. If TRUE, a progress bar will not be displayed. Defaults to FALSE.

Details

Several processing options can be performed in one call to warp() by passing the necessary command-line arguments. The following list describes several commonly used arguments. Note that gdalwarp supports a large number of arguments that enable a variety of different processing options. Users are encouraged to review the original source documentation provided by the GDAL project at the URL above for the full list.

The documentation for gdalwarp describes additional command-line options related to spatial reference systems, source nodata values, alpha bands, polygon cutlines as mask including blending, and more.

Mosaicing into an existing output file is supported if the output file already exists. The spatial extent of the existing file will not be modified to accommodate new data, so you may have to remove it in that case, or use the -overwrite option.

Command-line options are passed to warp() as a character vector. The elements of the vector are the individual options followed by their individual values, e.g.,

cl_arg = c("-tr", "30", "30", "-r", "bilinear"))

to set the target pixel resolution to 30 x 30 in target georeferenced units and use bilinear resampling.

Value

Logical indicating success (invisible TRUE). An error is raised if the operation fails.

Note

warp() can be used to reproject and also perform other processing such as crop, resample, and mosaic. This processing is generally done with a single function call by passing arguments for the target (output) pixel resolution, extent, resampling method, nodata value, format, and so forth. If warp() is called with t_srs set to "" (empty string), the target spatial reference will be set to that of src_files[1], so that the processing options given in cl_arg will be performed without reprojecting (in the case of one input raster or multiple inputs that all use the same spatial reference system, otherwise would reproject inputs to the SRS of src_files[1] when they are different).

See Also

GDALRaster-class, srs_to_wkt(), translate()

Examples

# reproject the elevation raster to NAD83 / CONUS Albers (EPSG:5070)
elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")

# command-line arguments for gdalwarp
# resample to 90-m resolution and keep pixels aligned:
args <- c("-tr", "90", "90", "-r", "cubic", "-tap")
# write to Erdas Imagine format (HFA) with compression:
args <- c(args, "-of", "HFA", "-co", "COMPRESSED=YES")

alb83_file <- file.path(tempdir(), "storml_elev_alb83.img")
warp(elev_file, alb83_file, t_srs="EPSG:5070", cl_arg = args)

ds <- new(GDALRaster, alb83_file)
ds$getDriverLongName()
ds$getProjectionRef()
ds$res()
ds$getStatistics(band=1, approx_ok=FALSE, force=TRUE)
ds$close()

deleteDataset(alb83_file)

[Package gdalraster version 1.11.1 Index]