Masks a SpatRaster to Alberta or to any user-supplied polygon.
The character shortcut "alberta" refers to the provincial
boundary packaged with sciSpatialR; any sf or SpatVector
polygon may also be passed directly.
Arguments
- x
A
SpatRasterto mask.- boundary
A
SpatVector, ansfpolygon, or the character shortcut"alberta". Defaults to"alberta", the packaged provincial boundary also returned byab_boundary().- inverse
Logical; if
TRUE, cells outside the boundary are retained and cells inside are set toNA. DefaultFALSE.- ...
Additional arguments passed to
terra::mask().
Examples
if (FALSE) { # \dontrun{
library(terra)
r <- rast(nrows = 100, ncols = 100,
xmin = -120, xmax = -110,
ymin = 49, ymax = 60,
crs = "EPSG:4326")
r[] <- runif(ncell(r))
# Mask to the default Alberta provincial boundary
r_ab <- mask_to_boundary(r)
# Mask to a user polygon
poly <- vect("my_polygon.gpkg")
r_masked <- mask_to_boundary(r, poly)
# Anything on the share works the same way
nsr <- get_layer("natural_regions_subregions_of_alberta")
r_nsr <- mask_to_boundary(r, nsr)
} # }