| gdalProject | R Documentation |
gdalwarpDEFUNCT: Please use the postProcessTo functions.
gdalResample is a thin wrapper around sf::gdal_utils('gdalwarp', ...) with specific options
set, notably, "-r", "near", -te, -te_srs, tr, -dstnodata = NA, -overwrite.
gdalMask is a thin wrapper around sf::gdal_utils('gdalwarp', ...) with specific options
set, notably, -cutline, -dstnodata = NA, and -overwrite.
gdalProject(
fromRas,
toRas,
filenameDest,
verbose = getOption("reproducible.verbose"),
...
)
gdalResample(
fromRas,
toRas,
filenameDest,
verbose = getOption("reproducible.verbose"),
...
)
gdalMask(
fromRas,
maskToVect,
writeTo = NULL,
verbose = getOption("reproducible.verbose"),
...
)
fromRas |
see |
toRas |
see |
filenameDest |
A filename with an appropriate extension (e.g., |
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., |
... |
For |
maskToVect |
see |
writeTo |
Optional character string of a filename to use |
gdalProject is a thin wrapper around sf::gdal_utils('gdalwarp', ...) with specific options
set, notably, -r to method (in the ...), -t_srs to the crs of the toRas,
-te to the extent of the toRas, -te_srs to the crs of the toRas,
-dstnodata = NA, and -overwrite.
These three functions were an alternative sequence
(gdalProject, gdalResample, gdalMask) for the from + projectTo
SpatRaster / maskTo SpatVector case in postProcessTo. The sequence
was determined to be faster and more accurate than any other ordering,
including running all three steps in one gdalwarp call (one-step
gdalwarp resulted in very coarse pixelation when converting from a
coarse resolution to fine resolution). They are retained for reference
only; the live postProcessTo path no longer dispatches to them.
gdalResample(), and gdalMask() and the overarching postProcessTo()
if (require("terra", quietly = TRUE)) {
# prepare dummy data -- 3 SpatRasters, 2 SpatVectors
# need 2 SpatRaster
rf <- system.file("ex/elev.tif", package = "terra")
elev1 <- terra::rast(rf)
# a polygon vector
f <- system.file("ex/lux.shp", package = "terra")
vOrig <- terra::vect(f)
v <- vOrig[1:2, ]
# utm <- terra::crs("epsg:23028") # $wkt
utm <- "+proj=utm +zone=28 +datum=WGS84 +units=m +no_defs"
vInUTM <- terra::project(vOrig, utm)
vAsRasInLongLat <- terra::rast(vOrig, resolution = 0.008333333)
res100 <- 100
rInUTM <- terra::rast(vInUTM, resolution = res100, vals = 1)
# crop, reproject, mask, crop a raster with a vector in a different projection
# --> gives message about not enough information
t1 <- postProcessTo(elev1, to = vInUTM)
# crop, reproject, mask a raster to a different projection, then mask
t2a <- postProcessTo(elev1, to = vAsRasInLongLat, maskTo = vInUTM)
t3a <- postProcessTo(elev1, to = rInUTM, maskTo = vInUTM)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.