Skip to contents

Create a Virtual Raster Dataset (VRT) from a collection of file-based raster datasets (tiles). See gdalbuildvrt for details.

Usage

# S4 method for character
vrt(x, filename="", options=NULL, overwrite=FALSE, set_names=FALSE, return_filename=FALSE)

Arguments

x

character. Filenames of raster "tiles". That is, files that have data for, typically non-overlapping, sub-regions of an raster. See makeTiles

filename

character. output VRT filename

options

character. All arguments as separate vector elements. Options as for gdalbuildvrt

overwrite

logical. Should filename be overwritten if it exists?

set_names

logical. Add the layer names of the first tile to the vrt?

return_filename

logical. If TRUE the filename is returned, otherwise a SpatRaster is returned

Value

SpatRaster

Note

A VRT can reference very many datasets. These are not all opened at the same time. The default is to open not more than 100 files. To increase performance, this maximum limit can be increased by setting the GDAL_MAX_DATASET_POOL_SIZE configuration option to a bigger value with setGDALconfig. Note that a typical user process on Linux is limited to 1024 simultaneously opened files.

See also

makeTiles to create tiles; makeVRT to create a .vrt file for a binary raster file that does not have a header file. vrt_tiles to get the filenames of the tiles in a VRT.

Examples

r <- rast(ncols=100, nrows=100)
values(r) <- 1:ncell(r)
x <- rast(ncols=2, nrows=2)
filename <- paste0(tempfile(), "_.tif")
ff <- makeTiles(r, x, filename)
ff
#> [1] "/var/folders/z4/sx941vhj3jd2jb9_gwftzctc0000gn/T//RtmplWWNMf/file42a75bb5022e_1.tif"
#> [2] "/var/folders/z4/sx941vhj3jd2jb9_gwftzctc0000gn/T//RtmplWWNMf/file42a75bb5022e_2.tif"
#> [3] "/var/folders/z4/sx941vhj3jd2jb9_gwftzctc0000gn/T//RtmplWWNMf/file42a75bb5022e_3.tif"
#> [4] "/var/folders/z4/sx941vhj3jd2jb9_gwftzctc0000gn/T//RtmplWWNMf/file42a75bb5022e_4.tif"

#vrtfile <- paste0(tempfile(), ".vrt")
#v <- vrt(ff, vrtfile)


## output in lower resolution
#vrtfile <- paste0(tempfile(), ".vrt")
#v <- vrt(ff, vrtfile, options = c("-tr", 5, 5))
#head(readLines(vrtfile))
#v