nearblack: Interface to GDAL's nearblack utility

Description Usage Arguments Value Author(s) Examples

View source: R/nearblack.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
nearblack(
  infile,
  o = infile,
  ...,
  of,
  white,
  color,
  near,
  nb,
  setalpha,
  setmask,
  q,
  co,
  dryrun = FALSE
)

Arguments

infile

Character. Path to a GDAL-supported readable datasource.

o

Optionally, a character string giving the path to a GDAL-supported output file. If not supplied, defaults to codeinfile=, indicating that the input file should be modified in place.

...

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

of, white, color, near, nb, setalpha, setmask, q, co

See the GDAL project's nearblack 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

Silently returns path to datasetname.

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
td <- tempdir()
a_rast <- file.path(td, "a.tif")
b_rast <- file.path(td, "b.tif")
file.copy(system.file("extdata/tahoe.tif", package = "gdalUtilities"),
          a_rast)
file.copy(system.file("extdata/tahoe.tif", package = "gdalUtilities"),
          b_rast)
nearblack(a_rast, b_rast, of = "GTiff", near = 150)

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