rReduce: Combine a raster stack after segregation

Description Usage Arguments Details Value See Also Examples

View source: R/modify.operators.R

Description

Successively combine the layers of a raster stack with each other (similar to Reduce).

Usage

1
2
rReduce(obj, by = NULL, fun = function(x) sum(x, na.rm = TRUE),
  weights = NULL, direction = "right")

Arguments

obj

[RasterLayer(1)]
The object to modify.

by

[list(.)]
the cell values by which the layers shall be aggregated; see Details.

fun

[function(1)]
find the resulting value of the combined layers.

weights

[numeric(length(obj))]
weight by which the values in each layer are multiplied before applying fun.

direction

[character(1)]
the direction into which the RasterLayer in obj is supposed to be combine. Either "right" (default) or "left"; see Details.

Details

The argument direction takes the direction into which the layers should be combined. "right" means that layers are combined from left to right. rReduce is based on the functional Reduce, where this wording is handled differently.

The number of layers in the aggregated raster depends on the length of the list in by. If by is left empty, everything is written into one RasterLayer object. Values to be aggregated in a RasterLayer are in the same list element.

Value

a RasterLayer or RasterStack of the same dimensions as obj, in which the layers of obj are aggregated into a smaller set of layers.

See Also

Other operators to modify a raster: rBlend, rRescale, rSegregate

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
input <- rtRasters$continuous
patches <- rPatches(rBinarise(input, thresh = 30))
myPatches <- rSegregate(patches)

# revert the segregation
visualise(rReduce(myPatches))

# group patches
twoGroups <- list(c(1:14), c(15:28))
visualise(rReduce(myPatches, by = twoGroups))

# select a subset of patches
someLayers <- list(c(1, 3, 5, 7, 9))
visualise(rReduce(myPatches, by = someLayers))

EhrmannS/rasterTools documentation built on Sept. 4, 2019, 10:34 a.m.