Last chance! 50% off unlimited learning
Sale ends in
translate()
is a wrapper of the gdal_translate
command-line
utility (see https://gdal.org/en/stable/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
.
translate(src_filename, dst_filename, cl_arg = NULL, quiet = FALSE)
Logical indicating success (invisible TRUE
).
An error is raised if the operation fails.
Character string. Filename of the source raster.
Character string. Filename of the output raster.
Optional character vector of command-line arguments for
gdal_translate
(see URL above).
Logical scalar. If TRUE
, a progress bar will not be
displayed. Defaults to FALSE
.
GDALRaster-class
, rasterFromRaster()
, warp()
ogr2ogr()
for vector data
# 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