This function can be used to mask inputs from data. Masking here is
equivalent to raster::mask
(though fastMask()
is used here)
or raster::intersect
.
maskInputs(x, studyArea, ...)
# S3 method for Raster
maskInputs(
x,
studyArea,
rasterToMatch = NULL,
maskWithRTM = NULL,
verbose = getOption("reproducible.verbose", 1),
...
)
# S3 method for Spatial
maskInputs(
x,
studyArea,
rasterToMatch = NULL,
maskWithRTM = FALSE,
verbose = getOption("reproducible.verbose", 1),
useCache = getOption("reproducible.useCache", FALSE),
...
)
# S3 method for SpatVector
maskInputs(
x,
studyArea,
rasterToMatch = NULL,
maskWithRTM = FALSE,
verbose = getOption("reproducible.verbose", 1),
useCache = getOption("reproducible.useCache", FALSE),
...
)
# S3 method for SpatRaster
maskInputs(
x,
studyArea,
rasterToMatch = NULL,
maskWithRTM = FALSE,
verbose = getOption("reproducible.verbose", 1),
useCache = getOption("reproducible.useCache", FALSE),
...
)
# S3 method for sf
maskInputs(
x,
studyArea,
verbose = getOption("reproducible.verbose", 1),
useCache = getOption("reproducible.useCache", FALSE),
...
)
An object to do a geographic raster::mask/raster::intersect. See methods.
SpatialPolygons*
object used for masking and possibly cropping
if no rasterToMatch
is provided.
If not in same CRS, then it will be spTransform
ed to
CRS of x
before masking. Currently, this function will not reproject the
x
. Optional in postProcess
.
Passed to methods. None currently implemented.
Template Raster*
object used for cropping (so extent should be
the extent of desired outcome) and reprojecting (including changing the
resolution and projection).
See details in postProcess()
.
Logical. If TRUE
, then the default,
Numeric, -1 silent (where possible), 0 being very quiet,
1 showing more messaging, 2 being more messaging, etc.
Default is 1. Above 3 will output much more information about the internals of
Caching, which may help diagnose Caching challenges. Can set globally with an
option, e.g., options('reproducible.verbose' = 0) to reduce to minimal
Logical, default getOption("reproducible.useCache", FALSE)
, whether
Cache
is used internally.
A GIS file (e.g., RasterLayer, SpatRaster etc.) that has been appropriately masked.
maskTo()
, postProcess()
for related examples
library(sp)
library(raster)
# make a SpatialPolygon
coords1 <- structure(c(-123.98, -117.1, -80.2, -100, -123.98, 60.9, 67.73, 65.58, 51.79, 60.9),
.Dim = c(5L, 2L))
Sr1 <- Polygon(coords1)
Srs1 <- Polygons(list(Sr1), "s1")
shpEcozone <- SpatialPolygons(list(Srs1), 1L)
crs(shpEcozone) <- "+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
# make a "study area" that is subset of larger dataset
coords <- structure(c(-118.98, -116.1, -99.2, -106, -118.98, 59.9, 65.73, 63.58, 54.79, 59.9),
.Dim = c(5L, 2L))
Sr1 <- Polygon(coords)
Srs1 <- Polygons(list(Sr1), "s1")
StudyArea <- SpatialPolygons(list(Srs1), 1L)
crs(StudyArea) <- crs(shpEcozone)
projString <- "+proj=utm +zone=15 +ellps=GRS80 +datum=NAD83 +units=m +no_defs"
StudyArea <- sp::spTransform(StudyArea, CRSobj = projString)
maskInputs(shpEcozone, StudyArea)
#> maskInputs with sf class objects is still experimental
#> intersecting ...
#> Checking for errors in SimpleFeature
#> Found no errors.
#> Checking for errors in SimpleFeature
#> Found no errors.
#> class : SpatialPolygonsDataFrame
#> features : 1
#> extent : -118.98, -99.2, 54.99269, 65.73 (xmin, xmax, ymin, ymax)
#> crs : +proj=longlat +datum=WGS84 +no_defs
#> variables : 0