rasterize_mask_cpp: Rasterize a vector polygon layer to a binary mask raster

View source: R/RcppExports.R

rasterize_mask_cppR Documentation

Rasterize a vector polygon layer to a binary mask raster

Description

Burns all polygon features from a vector source into a new single-band GeoTIFF raster that is spatially aligned to a reference raster. Pixels that fall inside at least one polygon are set to 1; all other pixels are set to 0.

Usage

rasterize_mask_cpp(vector_path, ref_raster_path, output_mask_path)

Arguments

vector_path

Character string: path to any OGR-readable vector source (shapefile, GeoJSON, GeoPackage, etc.).

ref_raster_path

Character string: path to a GDAL-readable raster used as the spatial reference (extent, resolution, CRS).

output_mask_path

Character string: file path where the output GDT_Byte GeoTIFF will be written (created or overwritten).

Details

This function is the low-level C++ entry point. Most users should call the higher-level create_mask wrapper instead.

Stops with an informative error if the package was built without GDAL support.

Value

Invisibly returns NULL. The side effect is the creation of the output mask raster at output_mask_path.

See Also

create_mask, apply_mask_cpp

Examples


if (has_gdal()) {
  # Requires GDAL support at build time.
  ref  <- system.file("extdata", "tiny.tif", package = "xbioclim")
  poly <- tempfile(fileext = ".geojson")
  mask <- tempfile(fileext = ".tif")
writeLines(
  '{"type":"FeatureCollection","features":[{"type":"Feature",
    "geometry":{"type":"Polygon","coordinates":[[[0,0],[1,0],[1,1],[0,1],[0,0]]]},
    "properties":{}}]}',
  poly)
  rasterize_mask_cpp(poly, ref, mask)
}


xbioclim documentation built on Oct. 5, 2026, 5:08 p.m.