rasterize | R Documentation |
Transfer values associated with the geometries of vector data to a raster
## S4 method for signature 'SpatVector,SpatRaster' rasterize(x, y, field="", fun, ..., background=NA, touches=FALSE, update=FALSE, sum=FALSE, cover=FALSE, filename="", overwrite=FALSE, wopt=list()) ## S4 method for signature 'matrix,SpatRaster' rasterize(x, y, values=1, fun, ..., background=NA, update=FALSE, filename="", overwrite=FALSE, wopt=list())
x |
SpatVector or a two-column matrix (point coordinates) |
y |
SpatRaster |
field |
character or numeric. If |
values |
typically a numeric vector of length |
fun |
function, summarizing function that returns a single number; for when there are multiple points in one cell. For example |
... |
additional arguments passed to |
background |
numeric. Value to put in the cells that are not covered by any of the features of |
touches |
logical. If |
update |
logical. If |
sum |
logical. If |
cover |
logical. If |
filename |
character. Output filename |
overwrite |
logical. If |
wopt |
list with additional arguments for writing files as in |
SpatRaster
rasterizeGeom
, rasterizeWin
, mask
r <- rast(xmin=0, ncols=18, nrows=18) # generate points set.seed(1) p <- spatSample(r, 1000, xy=TRUE, replace=TRUE) # rasterize points as a matrix x <- rasterize(p, r, fun=sum) y <- rasterize(p, r, value=1:nrow(p), fun=max) # rasterize points as a SpatVector pv <- vect(p) xv <- rasterize(pv, r, fun=sum) # Polygons f <- system.file("ex/lux.shp", package="terra") v <- vect(f) r <- rast(v, ncols=75, nrows=100) z <- rasterize(v, r, "NAME_2") plot(z) lines(v)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.