Skip to contents

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).

Value

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

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.

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")
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)
}
#> Warning: GDAL Error 4: /tmp/RtmpRzND6Y/file31e6786f16d9.tif: No such file or directory
#> NULL
# }