gdal_rasterize: Interface to GDAL's gdal_rasterize utility

Description Usage Arguments Value Author(s) Examples

View source: R/gdal_rasterize.R

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

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

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
if(requireNamespace("raster", quietly = TRUE)) {
    library(raster)
    ## Prepare file paths of example shapefile and template raster file
    vect_file <- system.file("external/lux.shp", package = "raster")
    td <- tempdir()
    rast_file <- file.path(td, "lux_rast.tif")

    ## Construct and save an appropriately sized 'empty' raster
    SPDF <- shapefile(vect_file)
    lonlatratio <- 1 / cospi(mean(coordinates(SPDF)[,2]) / 180)
    rr <- raster(extent(SPDF),
                 resolution = c(lonlatratio * 0.01, 0.01),
                 crs = crs(SPDF))
    ## 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(raster(rast_file))
}

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