Learn R Programming

CAWaR (version 0.0.2)

meStack: meStack

Description

Stacking of raster layers with different extents

Usage

meStack(x, y, z, agg.fun = mean, derive.stats = FALSE)

Arguments

x

A list of RasterLayer objects or a character vector with the paths to raster objects.

y

A spatial object from which an extent can be derived.

z

Object of class Date with the acquisition date for each element in x.

agg.fun

Function used to aggregate images collected in the same date. Default is the mean.

derive.stats

Logical argument. Default is FALSE.

Value

A list containing a RasterStack and related statistics.

Details

The function stacks the raster objects specified in x. For each element in x, the function crops it by the extent of y and, if their extents differ, fits the extent of x to the one of y. All new pixels are set to NA. If z is provided, the function will then aggregate all bands acquired in the same date using the function provide with agg.fun. If derive.stats is set to TRUE, the function will return basic statistics for each band (i.e. min, max, mean and sd) together with a plot of the mean values. The final output of the function is a list containing:

  • stack - RasterStack object.

  • dates - Acquisition dates for each layer in stack.

  • image.stats - Statistics for each band in the output RasterStack.

  • stats.plot - Plot showing the mean, minimum and maximum values per band.

  • control - Logical vector showing which elements in x where used to build the RasterStack.

Examples

Run this code
# NOT RUN {
{

require(raster)

r1 <- raster(xmn=1, xmx=90, ymn=1, ymx=90, res=1, vals=1) # image 1
r2 <- raster(xmn=50, xmx=150, ymn=50, ymx=150, res=1, vals=1) # image 2
r0 <- raster(xmn=20, xmx=90, ymn=50, ymx=90, res=1, vals=1) # target extent

crs(r0) <- crs(r2) <- crs(r1)

mes <- meStack(list(r1, r2), r0)
plot(mes$stack)

}
# }

Run the code above in your browser using DataLab