Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

rasterize

Rasterize vector data


Description

Transfer vector data to a raster

Usage

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

Arguments

x

SpatVector

y

SpatRaster

field

character or numeric. If field is a character, it should a variable name in x. If field is numeric it typically is a single number or a vector of length nrow(x). The values are recycled to nrow(x)

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. If touches=TRUE, add cannot be TRUE

update

logical. If TRUE, the values of the input SpatRaster are updated

sum

logical. If TRUE, the values of overlapping geometries are summed instead of replaced; and background is set to zero. Only used if x does not consists of points

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 at least 100 sub-cells (more of there are very few cells)

filename

character. Output filename

...

additional arguments for writing files as in writeRaster

Value

SpatRaster

Note

To update existing raster data use the output of rasterize as second argument in cover

See Also

Examples

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)

terra

Spatial Data Analysis

v1.2-10
GPL (>= 3)
Authors
Robert J. Hijmans [cre, aut] (<https://orcid.org/0000-0001-5872-2872>), Roger Bivand [ctb] (<https://orcid.org/0000-0003-2392-6140>), Karl Forner [ctb], Jeroen Ooms [ctb] (<https://orcid.org/0000-0002-4035-0289>), Edzer Pebesma [ctb] (<https://orcid.org/0000-0001-8049-7069>)
Initial release
2021-05-12

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.