f <- system.file("ex/lux.shp", package="terra")
v <- vect(f)
r <- rast(v, res=.1)
# length of lines
lns <- as.lines(v)
x <- rasterizeGeom(lns, r, fun="length", "km")
# count of points
set.seed(44)
pts <- spatSample(v, 100)
y <- rasterizeGeom(pts, r)
# area of polygons
pols <- buffer(pts, 1000)
z <- rasterizeGeom(pols, r, fun="area")
Run the code above in your browser using DataLab