polygon_to_raster: Create a raster from a polygon sf object

View source: R/conversion.R

polygon_to_rasterR Documentation

Create a raster from a polygon sf object

Description

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

Usage

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(s)

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


JGCRI/rgis documentation built on July 27, 2023, 1:47 p.m.