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.
This function can be used to crop or reproject module inputs from raw data.
A simple wrapper around the various different tools for these GIS types.
This function can be used to mask module inputs from raw data.
If filename2 is logical, then the cropped/masked
raster will be written to disk with the original targetFile name, with
"Small" prefixed to the basename(targetFilename).
If a character string, it will be the path of the saved raster.
It will be tested whether it is an absolute or relative path and used as is
if absolute or prepended with destinationPath if relative.
Can be used to write prepared inputs on disk.
# S3 method for spatialObjects postProcess(pp, filename1 = NULL, studyArea = NULL, rasterToMatch = NULL, overwrite = TRUE, useSAcrs = FALSE, useCache = getOption("reproducible.useCache", FALSE), ...) cropInputs(ci, studyArea, rasterToMatch, ...) # S3 method for default cropInputs(ci, studyArea, rasterToMatch, ...) # S3 method for spatialObjects cropInputs(ci, studyArea, rasterToMatch = NULL, extentToMatch = NULL, extentCRS = NULL, ...) projectInputs(pi, targetCRS, ...) # S3 method for Raster projectInputs(pi, targetCRS = NULL, rasterToMatch = NULL, ...) # S3 method for sf projectInputs(pi, targetCRS, ...) # S3 method for Spatial projectInputs(pi, targetCRS, ...) maskInputs(mi, studyArea, ...) # S3 method for Raster maskInputs(mi, studyArea, rasterToMatch, maskWithRTM = FALSE, ...) # S3 method for Spatial maskInputs(mi, studyArea, ...) determineFilename(filename2 = TRUE, filename1 = NULL, destinationPath = NULL, ...) writeOutputs(wo, filename2, overwrite, ...) # S3 method for Raster writeOutputs(wo, filename2, overwrite = FALSE, ...) # S3 method for Spatial writeOutputs(wo, filename2, overwrite = FALSE, ...) # S3 method for sf writeOutputs(wo, filename2, overwrite = FALSE, ...) # S3 method for default writeOutputs(wo, filename2, ...)
| pp | A |
||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| filename1 | Character string giving the file path of the input object,
if it has one. This is then used if |
||||||||||||||||
| studyArea |
|
||||||||||||||||
| rasterToMatch | Template |
||||||||||||||||
| overwrite | Logical. Should file being written overwrite an existing file if it exists. |
||||||||||||||||
| useSAcrs | Logical. If |
||||||||||||||||
| useCache | Passed to Cache in various places. Default |
||||||||||||||||
| ... | Additional arguments passed to ... passed to:
useSAcrs
** Will mask with NAs from rasterToMatch if maskWithRTM
|
||||||||||||||||
| ci | A |
||||||||||||||||
| extentToMatch | Optional. Can pass an extent here and a |
||||||||||||||||
| extentCRS | Optional. Can pass a |
||||||||||||||||
| pi | A |
||||||||||||||||
| targetCRS | The CRS of pi at the end of this function (i.e., the goal) |
||||||||||||||||
| mi | A |
||||||||||||||||
| maskWithRTM | Logical. If |
||||||||||||||||
| filename2 | Logical or character string (a file path) for the output file, after post processing, if saving is desired. See details. |
||||||||||||||||
| destinationPath | Optional. If |
||||||||||||||||
| wo | The object save to disk i.e., write outputs |
A file of the same type as starting, but with projection (and possibly other characteristics, including resolution, origin, extent if changed.
If filename2 is logical, then the output
filename will be "Small" prefixed to the basename(filename1).
If a character string, it
will be the path returned. It will be tested whether it is an
absolute or relative path and used as is if absolute or prepended with
destinationPath if provided, and if filename2 is relative.
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.
Post processing addresses several scenarios, and depending on which scenario,
file names are subtly different. For example, Raster objects may have
file-backed data, and so possess a file name, whereas Spatial
objects do not. Similarly, there may or may not be a desire to write an
object to disk after all post processing. This subtlety means that there are
two file names that may be at play: the "input" file name (filename1),
and the "output" filename (filename2).
When this is used only with post process, it is straight forward.
However, when postProcess is used within a prepInputs call,
the filename1 file is actually the file name of the downloaded file
(i.e., what name to give to the downloaded object) and the filename2
is the file name of the of post-processed file.
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
# download a zip file from internet, unzip all files, load as shapefile, Cache the call dPath <- file.path(tempdir(), "ecozones") shpEcozone <- prepInputs(destinationPath = dPath, url = "http://sis.agr.gc.ca/cansis/nsdb/ecostrat/zone/ecozone_shp.zip")#>#>#> | | | 0% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========= | 14% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |============= | 19% | |============== | 19% | |============== | 20% | |=============== | 21% | |================ | 23% | |================= | 24% | |================= | 25% | |================== | 26% | |=================== | 27% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |====================== | 31% | |======================= | 32% | |======================= | 33% | |======================= | 34% | |======================== | 34% | |======================== | 35% | |========================= | 35% | |========================= | 36% | |========================== | 37% | |========================== | 38% | |=========================== | 38% | |=========================== | 39% | |============================ | 39% | |============================ | 40% | |============================ | 41% | |============================= | 41% | |============================= | 42% | |============================== | 42% | |============================== | 43% | |============================== | 44% | |=============================== | 44% | |=============================== | 45% | |================================ | 45% | |================================ | 46% | |================================= | 46% | |================================= | 47% | |================================= | 48% | |================================== | 48% | |================================== | 49% | |=================================== | 49% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |===================================== | 54% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 56% | |======================================== | 57% | |======================================== | 58% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |=========================================== | 62% | |============================================ | 62% | |============================================ | 63% | |============================================ | 64% | |============================================= | 64% | |============================================= | 65% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 69% | |================================================= | 70% | |================================================= | 71% | |================================================== | 71% | |================================================== | 72% | |=================================================== | 72% | |=================================================== | 73% | |==================================================== | 74% | |==================================================== | 75% | |===================================================== | 75% | |===================================================== | 76% | |====================================================== | 76% | |====================================================== | 77% | |====================================================== | 78% | |======================================================= | 78% | |======================================================= | 79% | |======================================================== | 79% | |======================================================== | 80% | |======================================================== | 81% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 82% | |========================================================== | 83% | |========================================================== | 84% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |================================================================ | 92% | |================================================================= | 92% | |================================================================= | 93% | |================================================================= | 94% | |================================================================== | 94% | |================================================================== | 95% | |=================================================================== | 95% | |=================================================================== | 96% | |==================================================================== | 96% | |==================================================================== | 97% | |==================================================================== | 98% | |===================================================================== | 98% | |===================================================================== | 99% | |======================================================================| 99% | |======================================================================| 100%#>#>#>#>#>#> #> #>#>#>#' # Add a study area to Crop and Mask to # Create a "study area" library(sp) library(raster) coords <- structure(c(-122.98, -116.1, -99.2, -106, -122.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 shpEcozoneCropped <- cropInputs(shpEcozone, StudyArea)#>#>#>shpEcozoneMasked <- maskInputs(shpEcozone, StudyArea)#>#>#>