gdalwarp: Interface to GDAL's gdalwarp utility

Description Usage Arguments Value Author(s) Examples

View source: R/gdalwarp.R

Description

This function provides an interface mirroring that of the GDAL command-line app gdalwarp. For a description of the utility and the arguments that it takes, see the documentation at https://gdal.org/programs/gdalwarp.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
44
45
46
47
48
49
50
51
gdalwarp(
  srcfile,
  dstfile,
  ...,
  s_srs,
  t_srs,
  ct,
  to,
  novshiftgrid,
  order,
  tps,
  rpc,
  geoloc,
  et,
  refine_gcps,
  te,
  te_srs,
  tr,
  tap,
  ts,
  ovr,
  wo,
  ot,
  wt,
  r,
  srcnodata,
  dstnodata,
  srcalpha,
  nosrcalpha,
  dstalpha,
  wm,
  multi,
  q,
  IF,
  of,
  co,
  cutline,
  cl,
  cwhere,
  csql,
  cblend,
  crop_to_cutline,
  overwrite,
  nomd,
  cvmd,
  setci,
  oo,
  doo,
  config,
  dryrun = FALSE
)

Arguments

srcfile

Character. Path to a GDAL-supported readable datasource.

dstfile

Character. Path to a GDAL-supported output file.

...

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

s_srs, t_srs, ct, to, novshiftgrid, order, tps, rpc, geoloc, et

See the GDAL project's gdalwarp documentation for details.

refine_gcps, te, te_srs, tr, tap, ts, ovr, wo, ot, wt, r, srcnodata

See the GDAL project's gdalwarp documentation for details.

dstnodata, srcalpha, nosrcalpha, dstalpha, wm, multi, q, IF, of, co

See the GDAL project's gdalwarp documentation for details.

cutline, cl, cwhere, csql, cblend, crop_to_cutline, overwrite

See the GDAL project's gdalwarp documentation for details.

nomd, cvmd, setci, oo, doo, config

See the GDAL project's gdalwarp 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
## Prepare file paths
td <- tempdir()
in_tif <- file.path(td, "tahoe.tif")
gcp_tif <- file.path(td, "tahoe_gcp.tif")
out_tif <- file.path(td, "tahoe_warped.tif")

## Set up some ground control points, then warp
file.copy(system.file("extdata/tahoe.tif", package = "gdalUtilities"),
          in_tif)
## Four numbers: column, row, x-coord, y-coord
gcp <- matrix(c(100, 300, -119.93226, 39.28977,  ## A
                0,   300, -119.93281, 39.28977,  ## B
                100, 400, -119.93226, 39.28922,  ## C
                0,   400, -119.93281, 39.28922,  ## lower-left
                400,   0, -119.93067, 39.29136,  ## upper-right
                400, 400, -119.93062, 39.28922,  ## lower-right
                0,     0, -119.93281, 39.29141), ## upper-left
              ncol = 4, byrow = TRUE)

## Add ground control points. (For some reason, this drops CRS, so
## it needs to be explicitly given via `a_srs` argument.)
gdal_translate(in_tif, gcp_tif, gcp = gcp, a_srs = "EPSG:4326")
gdalwarp(gcp_tif, out_tif, r = "bilinear")

## Check that it worked
if(requireNamespace("raster", quietly = TRUE)) {
  library(raster)
  if(require(rasterVis)) {
    r1 <- raster(in_tif)
    p1 <- levelplot(r1, margin = FALSE, colorkey = FALSE)
    r2 <- raster(out_tif)
    p2 <- levelplot(r2, margin = FALSE, colorkey = FALSE)
    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.