Creates a raster from a polygon sf object using the fasterize library and function which provides great improvement over raster::rasterize. See https://cran.r-project.org/web/packages/fasterize/fasterize.pdf

polygon_to_raster(sf, raster, field = NULL, fun, background = NA_real_,
  by = NULL)

Arguments

sf

an sf::sf() object with a geometry column of POLYGON and/or MULTIPOLYGON objects

raster

A raster object. Used as a template for the raster output. Can be created with raster::raster()

field

character. The name of a column in sf, providing a value for each of the polygons rasterized. If NULL (default), all polygons will be given a value of 1

fun

character. The name of a function by which to combine overlapping polygons. Currently takes "sum", "first", "last", "min", "max", "count", or "any". Future versions may include more functions or the ability to pass custom R/C++ functions. If you need to summarize by a different function, useby= to get a RasterBrick and then raster::stackApply() or raster::calc() to summarize

background

numeric. Value to put in the cells that are not covered by any of the features of x. Default is NA.

by

character. The name of a column in sf by which to aggregate layers. If set, fasterize will return a RasterBrick with as many layers as unique values of the by column

Value

raster object

Author

Chris R. Vernon (chris.vernon@pnnl.gov)