gdal_rasterize: Interface to GDAL's gdal_rasterize utility

View source: R/gdal_rasterize.R

gdal_rasterizeR Documentation

Interface to GDAL's gdal_rasterize utility

Description

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

Usage

gdal_rasterize(
  src_datasource,
  dst_filename,
  ...,
  b,
  i,
  at,
  burn,
  a,
  threeD,
  add,
  l,
  where,
  sql,
  dialect,
  of,
  a_srs,
  to,
  co,
  a_nodata,
  init,
  te,
  tr,
  tap,
  ts,
  ot,
  optim,
  q,
  config_options = character(0),
  dryrun = FALSE
)

Arguments

src_datasource

Character. Path to a GDAL-supported readable datasource.

dst_filename

Character. Path to a GDAL-supported output file.

...

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

b, i, at, burn, a, threeD, add, l, where, sql, dialect, of

See the GDAL project's gdal_rasterize documentation for details.

a_srs, to, co, a_nodata, init, te, tr, tap, ts, ot, optim, q

See the GDAL project's gdal_rasterize 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_filename.

Author(s)

Joshua O'Brien

Examples


if(require(terra)) {
    ## Prepare file paths of example shapefile and template raster file
    vect_file <- system.file("ex/lux.shp", package = "terra")
    td <- tempdir()
    rast_file <- file.path(td, "lux_rast.tif")

    ## Construct and save an appropriately sized 'empty' raster
    LUX <- vect(vect_file)
    lonlatratio <- 1 / cospi(mean(geom(LUX)[, "y"]) / 180)
    rr <- rast(ext(LUX),
               resolution = c(lonlatratio * 0.01, 0.01),
               crs = crs(LUX), vals = NA)

    ## Note: this next line warns that raster is empty
    writeRaster(rr, filename = rast_file, overwrite = TRUE)

    ## Rasterize polygon using empty raster and check that it worked
    gdal_rasterize(vect_file, rast_file, a = "ID_2")
    plot(rast(rast_file))
}


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