stackRasterList: Converts a list of rasters, possibly with different...

View source: R/stackRasterList.R

stackRasterListR Documentation

Converts a list of rasters, possibly with different projections and resolutions, to a single raster stack.

Description

This function is intended to be used prior to passing covariates to krigeLgm in order for the rasters for all covariates to have the same projection and same resolution.

Usage

stackRasterList(x, template = x[[1]], method = "near", mc.cores=NULL)
spdfToBrick(x, 
    template,
    logSumExpected=FALSE,
    pattern = '^expected_[[:digit:]]+$'
)

Arguments

x

A list of SpatRaster or SpatVectors for stackRasterList and spdfToBrick respectively

template

A raster whose projection and resolution all other rasters will be aligned with.

method

The method to use, either "near", or "bilinear". Can be a vector of the same length as x to specify different methods for each raster. If method has names which correspond to the names of x, the names will be used instead of the order to assign methods to rasters.

mc.cores

If non-null, mclapply is used with this argument specifying the number of cores.

logSumExpected

return the log of the sum of offsets

pattern

expression to identify layers to rasterize in x

Value

A raster brick, with one layer for each variable.

Examples


myCrs = crs("+proj=utm +zone=17 +ellps=GRS80 +units=m +no_defs")
x = list(a=rast(matrix(1:9, 3, 3), extent=ext(0,1,0,1), 
       crs=myCrs),
	b=rast(matrix(1:25, 5, 5), extent=ext(-1, 2, -1, 2),
	   crs=myCrs)
	)
mystack = stackRasterList(x)
mystack



mylist = list(
	a=rast(matrix(1:36, 6, 6,byrow=TRUE), extent=ext(0,1000,0,1000), 
       crs=myCrs),
	b=rast(matrix(1:144, 12, 12), extent=ext(-200, 200, -200, 200),
	   crs=myCrs),
	c=rast(matrix(1:100, 10, 10), extent=ext(-5000,5000,-5000,5000), 
       crs=myCrs)
	)
	
	mystack = stackRasterList(mylist, mc.cores=1)
	mystack

plot(mystack[["b"]], main="stack b")
plot(mystack[['a']],add=TRUE,col=grey(seq(0,1,len=12)),alpha=0.8,legend=FALSE)


geostatsp documentation built on Dec. 24, 2024, 3 a.m.