This function is a wrapper for gdalUtilities::gdalwarp()
for use with
terra objects.
Usage
terra_gdal_project(
x,
y,
method = "bilinear",
n_threads = 1,
filename = tempfile(fileext = ".tif"),
datatype = "FLT4S",
cache_limit = 200,
tiled = FALSE,
bigtiff = FALSE,
compress = "LZW",
verbose = TRUE,
NAflag = NULL,
output_raster = TRUE
)
Arguments
- x
terra::rast()
Raster object with source data.- y
terra::rast()
Raster object specifying spatial properties for output data.- method
character
Name of interpolation method.- n_threads
integer
Number of computational threads to use for data processing. To reduce run time, it is strongly recommended to set this parameter based on available resources (see Examples section below). Defaults to 1.- filename
character
Filename for output raster. Defaults totempfile(fileext = ".tif")
.- datatype
character
Value indicating the data type for saving data. Defaults to"FLT4S"
.- cache_limit
integer
Number of MB to use for GDAL caching. Defaults to 200.- tiled
logical
Value indicating if GeoTIFF files should be tiled. Defaults toFALSE
.- bigtiff
logical
Value indicating the data should be stored in BIGTIFF format. Defaults toFALSE
.- compress
character
Value indicating compression format. Available options include"LZW"
and"DEFLATE"
. Defaults to"LZW"
.- verbose
logical
Should information be displayed during processing? Defaults toTRUE
.- NAflag
numeric
Value for representing missing (NA
) values. A"none"
value can also be used to indicate that no flag should be set. Defaults toNULL
such that the value is determined automatically.- output_raster
logical
Should a raster (terra::rast()
) object be returned? IfFALSE
then the file path for the resulting file is returned. Defaults toTRUE
.
Value
A terra::rast()
raster object.
Examples
# please ensure that the gdalUtilities package is installed
# to run this example
# create raster with data
x <- rast(
ncols = 40, nrows = 40, xmin = -110, xmax = -90, ymin = 40, ymax=60,
crs = "+proj=longlat +datum=WGS84"
)
values(x) <- seq_len(ncell(x))
# create raster to define spatial properties for projection
y <- rast(
ncols = 94, nrows = 124, xmin = -944881, xmax = 935118, ymin = 4664377,
ymax = 7144377,
crs = "+proj=lcc +lat_1=48 +lat_2=33 +lon_0=-100 +datum=WGS84"
)
# project data
z <- terra_gdal_project(x, y)
# preview result
print(z)
#> class : SpatRaster
#> dimensions : 124, 94, 1 (nrow, ncol, nlyr)
#> resolution : 19999.99, 20000 (x, y)
#> extent : -944881, 935118, 4664377, 7144377 (xmin, xmax, ymin, ymax)
#> coord. ref. : +proj=lcc +lat_0=0 +lon_0=-100 +lat_1=48 +lat_2=33 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs
#> source : file16f3fc7fb3778a.tif
#> name : lyr.1