fasterize2: Rasterize following crop and reproject

View source: R/GIS.R

fasterize2R Documentation

Rasterize following crop and reproject

Description

A simple wrapper around terra::rasterize().

Usage

fasterize2(emptyRaster, polygonToFasterize, field)

Arguments

emptyRaster

An empty RasterLayer orSpatRaster to use as a template.

polygonToFasterize

an sf or SpatVector object, which will be cropped first if extent(emptyRaster) < extent(polygonToFasterize).

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)

Value

an object of the same class as emptyRaster

Examples


## using sf + raster
f1 <- system.file("external/lux.shp", package = "raster")
v1 <- sf::st_read(f1)
r1 <- raster::raster(v1, ncols = 75, nrows = 100)
raster::crs(r1) <- "epsg:4326"
z1 <- fasterize2(r1, v1, "NAME_2")

## using terra
f2 <- system.file("ex/lux.shp", package = "terra")
v2 <- terra::vect(f2)
r2 <- terra::rast(v2, ncols = 75, nrows = 100)
z2 <- fasterize2(r2, v2, "NAME_2")

terra::compareGeom(terra::rast(z1), z2)

PredictiveEcology/map documentation built on June 15, 2025, 6:15 a.m.