apply_mask_cpp: Apply a binary mask raster to an input raster

View source: R/RcppExports.R

apply_mask_cppR Documentation

Apply a binary mask raster to an input raster

Description

Reads input_path and mask_path tile-by-tile (one row at a time) and writes the result to output_path. Pixels where the mask equals 0 are replaced with NaN in the output; all other pixels retain their original values (with any GDAL scale/offset applied).

Usage

apply_mask_cpp(input_path, mask_path, output_path)

Arguments

input_path

Character string: path to a GDAL-readable raster (any number of bands).

mask_path

Character string: path to a single-band GDT_Byte mask raster (e.g., produced by rasterize_mask_cpp).

output_path

Character string: file path where the output Float64 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 or if the mask and input dimensions differ.

Value

Invisibly returns NULL. The side effect is the creation of the masked raster at output_path.

See Also

create_mask, rasterize_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")
  output <- 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)
  apply_mask_cpp(ref, mask, output)
}


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