gdal_translate: Interface to GDAL's gdal_translate utility

Description Usage Arguments Value Author(s) Examples

View source: R/gdal_translate.R

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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_scale,
  a_offset,
  a_ullr,
  a_nodata,
  colorinterp,
  mo,
  co,
  nogcp,
  gcp,
  q,
  sds,
  stats,
  noxmp,
  norat,
  oo,
  sd_index,
  config,
  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_scale, a_offset, a_ullr, a_nodata,

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, config

See the GDAL project's gdal_translate documentation for details.

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

None. Called instead for its side effect.

Author(s)

Joshua O'Brien

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
## 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(requireNamespace("raster", quietly = TRUE)) {
  library(raster)
  if(require(rasterVis)) {
    r1 <- raster(in_raster)
    r1[is.na(r1)] <- 0
    r1 <- as.factor(r1)
    rat <- levels(r1)[[1]]
    rat[["landcover"]] <- c("water", "land")
    levels(r1) <- rat
    p1 <- levelplot(r1, margin = FALSE, colorkey = FALSE,
                    col.regions = c("lightblue", "brown"))

    r2 <- raster(out_raster)
    r2[is.na(r2)] <- 0
    r2 <- as.factor(r2)
    rat <- levels(r2)[[1]]
    rat[["landcover"]] <- c("water", "land")
    levels(r2) <- rat
    p2 <- levelplot(r2, margin = FALSE, colorkey = FALSE,
                    col.regions = c("lightblue", "brown"))

    plot(p1, split = c(1, 1, 2, 1))
    plot(p2, split = c(2, 1, 2, 1), newpage = FALSE)

  }
}

gdalUtilities documentation built on Oct. 26, 2021, 5:06 p.m.