Generic function to post process objects
The method for spatialObjects (Raster* and Spatial*) will
crop, reproject, and mask, in that order. This function is a wrapper for
cropInputs, fixErrors, projectInputs,
maskInputs and
writeOutputs, with a decent amount of data manipulating
between these calls so that the crs match.
postProcess(x, ...) # S3 method for spatialObjects postProcess(x, filename1 = NULL, filename2 = TRUE, studyArea = NULL, rasterToMatch = NULL, overwrite = TRUE, useSAcrs = FALSE, useCache = getOption("reproducible.useCache", FALSE), ...)
| x | An object of postProcessing, e.g., |
||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ... | Additional arguments passed to methods. For ... passed to:
useSAcrs
** Will mask with NAs from rasterToMatch if maskWithRTM
|
||||||||||||||||
| filename1 | Character strings giving the file paths of
the input object ( |
||||||||||||||||
| filename2 |
|
||||||||||||||||
| studyArea |
|
||||||||||||||||
| rasterToMatch | Template |
||||||||||||||||
| overwrite | Logical. Should downloading and all the other actions occur even if they pass the checksums or the files are all there. |
||||||||||||||||
| useSAcrs | Logical. If |
||||||||||||||||
| useCache | Passed to Cache in various places. Default |
If the rasterToMatch or studyArea are passed, then
the following sequence will occur:
Fix errors fixErrors. Currently only errors fixed are for
SpatialPolygons using buffer(..., width = 0).
Crop using cropInputs
Project using projectInputs
Mask using maskInputs
Determine file name determineFilename
Write that file name to disk, optionally writeOutputs
NOTE: checksumming does not occur during the post-processing stage, as
there are no file downloads. To achieve fast results, wrap
prepInputs with Cache
NOTE: sf objects are still very experimental.
rasterToMatch and/or studyAreaDepending on which of these were passed, different things will happen to the
targetFile located at filename1.
targetFile is a Raster* object:rasterToMatch | studyArea | Both | |
extent | Yes | Yes | rasterToMatch |
resolution | Yes | No | rasterToMatch |
projection | Yes | No* | rasterToMatch* |
alignment | Yes | No | rasterToMatch |
mask | No** | Yes | studyArea** |
rasterToMatch | studyArea |
useSAcrs
** Will mask with NAs from rasterToMatch if maskWithRTM
targetFile is a Spatial* object:rasterToMatch | studyArea | Both | |
extent | Yes | Yes | rasterToMatch |
resolution | NA | NA | NA |
projection | Yes | No* | rasterToMatch* |
alignment | NA | NA | NA |
mask | No | Yes | studyArea |
rasterToMatch | studyArea |
useSAcrs
prepInputs
# Add a study area to Crop and Mask to # Create a "study area" library(sp) library(raster) ow <- setwd(tempdir()) # 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) <- "+init=epsg:4326 +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) <- "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0" #' #' ########## shpEcozonePostProcessed <- postProcess(shpEcozone, studyArea = StudyArea)#>#>#>#>#>#>#>#>#>#' # Try manually, individual pieces shpEcozoneReprojected <- projectInputs(shpEcozone, StudyArea) shpEcozoneCropped <- cropInputs(shpEcozone, StudyArea)#>#>#>#>#>#>setwd(ow)