| gdal_rasterize {gdalUtilities} | R 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  | 
| dryrun | Logical (default  | 
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))
}