gdal_translate: Interface to GDAL's gdal_translate utility

View source: R/gdal_translate.R

gdal_translateR Documentation

Interface to GDAL's gdal_translate utility

Description

This function provides an interface mirroring that of the GDAL command-line app gdal_translate. For a description of the utility and the arguments that it takes, see the documentation at https://gdal.org/programs/gdal_translate.html.

Usage

gdal_translate(
  src_dataset,
  dst_dataset,
  ...,
  ot,
  strict,
  IF,
  of,
  b,
  mask,
  expand,
  outsize,
  tr,
  r,
  scale,
  exponent,
  unscale,
  srcwin,
  projwin,
  projwin_srs,
  srs,
  epo,
  eco,
  a_srs,
  a_coord_epoch,
  a_ullr,
  a_nodata,
  a_scale,
  a_offset,
  colorinterp,
  mo,
  co,
  nogcp,
  gcp,
  q,
  sds,
  stats,
  noxmp,
  norat,
  oo,
  sd_index,
  config_options = character(0),
  dryrun = FALSE
)

Arguments

src_dataset

Character. Path to a GDAL-supported readable datasource.

dst_dataset

Character. Path to a GDAL-supported output file.

...

Here, a placeholder argument that forces users to supply exact names of all subsequent formal arguments.

ot, strict, IF, of, b, mask, expand, outsize, tr, r, scale, exponent

See the GDAL project's gdal_translate documentation for details.

unscale, srcwin, projwin, projwin_srs, srs, epo, eco

See the GDAL project's gdal_translate documentation for details.

a_srs, a_coord_epoch, a_ullr, a_nodata, a_scale, a_offset

See the GDAL project's gdal_translate documentation for details.

colorinterp

Along with colorinterp, arguments named colorinterp_bn, where bn refers the number of a band are also allowed. See the GDAL project's gdal_translate documentation for details.

mo, co, nogcp, gcp, q, sds, stats, norat, noxmp, oo, sd_index

See the GDAL project's gdal_translate documentation for details.

config_options

A named character vector with GDAL config options, of the form c(option1=value1, option2=value2). (See here for a complete list of supported config options.)

dryrun

Logical (default FALSE). If TRUE, instead of executing the requested call to GDAL, the function will print the command-line call that would produce the equivalent output.

Value

Silently returns path to dst_dataset.

Author(s)

Joshua O'Brien

Examples


## Prepare file paths
td <- tempdir()
in_raster <- file.path(td, "europe.tif")
out_raster <- file.path(td, "europe_small.tif")
file.copy(system.file("extdata/europe.tif", package = "gdalUtilities"),
          to = td)

## Shrink a tiff by 50% in both x and y dimensions
gdal_translate(in_raster, out_raster, outsize = c("50%","50%"))

## Check that it worked
if(require(terra)) {

  r1 <- rast(in_raster)
  r1[is.na(r1)] <- 0
  r1 <- as.factor(r1)
  rat <- levels(r1)[[1]]
  rat[["landcover"]] <- c("water", "land")
  levels(r1) <- rat

  r2 <- rast(out_raster)
  r2[is.na(r2)] <- 0
  r2 <- as.factor(r2)
  rat <- levels(r2)[[1]]
  rat[["landcover"]] <- c("water", "land")
  levels(r2) <- rat

  op <- par(mfcol = c(1, 2))
  plot(r1, col = c("lightblue", "brown"), legend = FALSE)
  plot(r2, col = c("lightblue", "brown"), legend = FALSE)
  par(op) ## Reset pre-existing parameters
}


gdalUtilities documentation built on Aug. 10, 2023, 5:08 p.m.