Learn R Programming

terra (version 1.1-4)

rasterize: Rasterize vector data

Description

Transfer vector data to a raster

Usage

# S4 method for SpatVector,SpatRaster
rasterize(x, y, field, fun, background=NA, update=FALSE, touches=is.lines(x),
	cover=FALSE, filename="", ...)

Arguments

x

SpatVector

y

SpatRaster

field

character, numeric, or missing. If field is a character, it should a variable name in x or vector of values if fun can handle these. If field is numeric it should be a single number (index the variable), or a vector with the same length as x. If it is missing, 1:nrow(x) is used

fun

function, summarizing function that returns a single number; for when there are multiple points in one cell. For example mean, length (to get a count), min or max. Only used if x consists of points

background

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

touches

logical. If TRUE, all cells touched by lines or polygons are affected, not just those on the line render path, or whose center point is within the polygon

update

logical. If TRUE, the values of the SpatRaster are updated for the cells that overlap with the geometries of x. Default is FALSE

cover

logical. If TRUE and the geometry of x is polygons, the fraction of a cell that is covered by the polygons is returned. This is estimated by determining presence/absence of the polygon in the each subcell

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

See Also

mask

Examples

Run this code
# NOT RUN {
f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
r <- rast(v, ncol=75, nrow=100)
#x <- rasterize(v, r, "NAME_2")

#plot(x)
#lines(v)
# }

Run the code above in your browser using DataLab