Learn R Programming

gdalUtilities (version 1.2.5)

nearblack: Interface to GDAL's nearblack utility

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

nearblack(
  infile,
  o = infile,
  ...,
  of,
  white,
  color,
  near,
  nb,
  setalpha,
  setmask,
  q,
  co,
  config_options = character(0),
  dryrun = FALSE
)

Value

Silently returns path to o.

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.

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.

Author

Joshua O'Brien

Examples

Run this code
# \donttest{
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(require(terra)) {
    op <- par(mfcol = c(1, 2))
    r1 <- plot(rast(a_rast))
    r2 <- plot(rast(b_rast))
    par(op) ## Reset preexisting parameters
}
# }

Run the code above in your browser using DataLab