Learn R Programming

gdalraster (version 1.11.1)

translate: Convert raster data between different formats

Description

translate() is a wrapper of the gdal_translate command-line utility (see https://gdal.org/programs/gdal_translate.html). The function can be used to convert raster data between different formats, potentially performing some operations like subsetting, resampling, and rescaling pixels in the process. Refer to the GDAL documentation at the URL above for a list of command-line arguments that can be passed in cl_arg.

Usage

translate(src_filename, dst_filename, cl_arg = NULL, quiet = FALSE)

Value

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

Arguments

src_filename

Character string. Filename of the source raster.

dst_filename

Character string. Filename of the output raster.

cl_arg

Optional character vector of command-line arguments for gdal_translate (see URL above).

quiet

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

See Also

GDALRaster-class, rasterFromRaster(), warp()

ogr2ogr() for vector data

Examples

Run this code
# convert the elevation raster to Erdas Imagine format and resample to 90m
elev_file <- system.file("extdata/storml_elev.tif", package="gdalraster")

# command-line arguments for gdal_translate
args <- c("-tr", "90", "90", "-r", "average")
args <- c(args, "-of", "HFA", "-co", "COMPRESSED=YES")

img_file <- file.path(tempdir(), "storml_elev_90m.img")
translate(elev_file, img_file, args)

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

deleteDataset(img_file)

Run the code above in your browser using DataLab