This function is deprecated. Use cropTo. If used, all arguments will be passed to cropTo anyway.

fixErrors --> fixErrosTerra

Deprecated. Use projectTo().

maskInputs is deprecated. Use maskTo()

See writeTo()

cropInputs(
  x,
  studyArea,
  rasterToMatch,
  verbose = getOption("reproducible.verbose", 1),
  ...
)

# S3 method for default
cropInputs(x, ...)

fixErrors(
  x,
  objectName,
  attemptErrorFixes = TRUE,
  useCache = getOption("reproducible.useCache", FALSE),
  verbose = getOption("reproducible.verbose", 1),
  testValidity = getOption("reproducible.testValidity", TRUE),
  ...
)

# S3 method for default
fixErrors(
  x,
  objectName,
  attemptErrorFixes = TRUE,
  useCache = getOption("reproducible.useCache", FALSE),
  verbose = getOption("reproducible.verbose", 1),
  testValidity = getOption("reproducible.testValidity", TRUE),
  ...
)

projectInputs(
  x,
  targetCRS,
  verbose = getOption("reproducible.verbose", 1),
  ...
)

# S3 method for default
projectInputs(x, targetCRS, ...)

maskInputs(x, studyArea, ...)

writeOutputs(
  x,
  ...,
  overwrite = getOption("reproducible.overwrite", NULL),
  verbose = getOption("reproducible.verbose", 1)
)

# S3 method for default
writeOutputs(
  x,
  ...,
  overwrite = getOption("reproducible.overwrite", FALSE),
  verbose = getOption("reproducible.verbose", 1)
)

Arguments

x

The object save to disk i.e., write outputs

studyArea

SpatialPolygons* object used for masking and possibly cropping if no rasterToMatch is provided. If not in same CRS, then it will be spTransformed to CRS of x before masking. Currently, this function will not reproject the x. Optional in postProcess.

rasterToMatch

Template Raster* object passed to the to argument of projectTo(), thus will changing the resolution and projection of x. See details in postProcessTo().

verbose

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

...

Passed into writeTo()

objectName

Optional. This is only for messaging; if provided, then messages relayed to user will mention this.

attemptErrorFixes

Will attempt to fix known errors. Currently only some failures for SpatialPolygons* are attempted. Notably with terra::buffer(..., width = 0). Default TRUE, though this may not be the right action for all cases.

useCache

Logical, default getOption("reproducible.useCache", FALSE), whether Cache is used on the internal terra::buffer command.

testValidity

Logical. If TRUE, the a test for validity will happen before actually running buffering (which is the solution in most cases). However, sometimes it takes longer to test for validity than just buffer without testing (there are no consequences of buffering if everything is valid). If FALSE, then the test will be skipped and the buffering will happen regardless. If NA, then all testing and buffering will be skipped.

targetCRS

The CRS of x at the end of this function (i.e., the goal)

overwrite

Logical. Should file being written overwrite an existing file if it exists.

Value

A GIS file (e.g., RasterLayer, SpatRaster etc.) that has been appropriately cropped.

A GIS file (e.g., RasterLayer, SpatRaster etc.) that has been attempted to be fixed, if it finds errors.

A file of the same type as starting, but with projection (and possibly other characteristics, including resolution, origin, extent if changed).

A GIS file (e.g., RasterLayer, SpatRaster etc.) that has been appropriately reprojected.

A GIS file (e.g., RasterLayer, SpatRaster etc.) that has been appropriately masked.

A GIS file (e.g., SpatRaster etc.) that has been appropriately written to disk. In the case of vector datasets, this will be a side effect. In the case of gridded objects (Raster*, SpatRaster), the object will have a file-backing.

Author

Eliot McIntire, Jean Marchal, Ian Eddy, and Tati Micheletti

Eliot McIntire and Jean Marchal

Examples

if (requireNamespace("terra", quietly = TRUE)) {
  r <- terra::rast(terra::ext(0, 100, 0, 100), vals = 1:1e2)

  tf <- tempfile(fileext = ".tif")
  writeOutputs(r, tf)
}
#>     writing...
#> ...done in 0.0315 secs
#> class       : SpatRaster 
#> dimensions  : 10, 10, 1  (nrow, ncol, nlyr)
#> resolution  : 10, 10  (x, y)
#> extent      : 0, 100, 0, 100  (xmin, xmax, ymin, ymax)
#> coord. ref. :  
#> source      : file245a4a3cf9b8.tif 
#> name        : lyr.1 
#> min value   :     1 
#> max value   :   100