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).
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_Bytemask raster (e.g., produced byrasterize_mask_cpp).- output_path
Character string: file path where the output
Float64GeoTIFF 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.
Examples
# \donttest{
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)
}
#> Warning: /tmp/RtmpRzND6Y/file31e6716919d0.tif: No such file or directory (GDAL error 4)
#> NULL
# }