rasterize,GVector,GRaster-method | R Documentation |
The rasterize()
function converts a GVector
into a GRaster
.
## S4 method for signature 'GVector,GRaster'
rasterize(x, y, field = "", background = NA, by = NULL, verbose = TRUE)
x |
A |
y |
A |
field |
Character: Name of a column in the data table of |
background |
Numeric or |
by |
Either |
verbose |
Logical: If |
A GRaster
.
terra::rasterize()
, GRASS module v.to.rast
(see grassHelp("v.to.rast")
)
if (grassStarted()) {
# Setup
library(sf)
library(terra)
# Elevation raster, outline of a part of Madagascar, and rivers vector:
madElev <- fastData("madElev") # raster
madDypsis <- fastData("madDypsis") # points vector
madRivers <- fastData("madRivers") # lines vector
madCoast4 <- fastData("madCoast4") # polygons vector
# Convert to GRaster and GVectors:
elev <- fast(madElev)
dypsis <- fast(madDypsis)
coast4 <- fast(madCoast4)
rivers <- fast(madRivers)
# Convert points, line, and polygons vectors to rasters:
points <- rasterize(dypsis, elev)
plot(points)
lines <- rasterize(rivers, elev)
plot(lines)
polys <- rasterize(coast4, elev)
plot(polys)
communes <- rasterize(coast4, elev, field = "NAME_4")
plot(communes)
# Change background value:
polysNeg1 <- rasterize(coast4, elev, background = -1)
plot(polysNeg1)
# Make one layer per river:
byRiver <- rasterize(rivers, elev, field = "NAM", by = "NAM")
plot(byRiver)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.