| apply_mask_cpp | R Documentation |
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).
apply_mask_cpp(input_path, mask_path, output_path)
input_path |
Character string: path to a GDAL-readable raster (any number of bands). |
mask_path |
Character string: path to a single-band |
output_path |
Character string: file path where the output
|
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.
Invisibly returns NULL. The side effect is the creation
of the masked raster at output_path.
create_mask, rasterize_mask_cpp
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)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.