Create a RasterLayer from a TransitionLayer with a call to
the generic function raster
. The n x n transition matrix of
the TransitionLayer is transformed to form the values n cells of a raster.
# S4 method for TransitionLayer
raster(x, reduceMethod = "NZcolMeans")
an object of class Transition*
character for the method to reduce the transition matrix. See details
a RasterLayer
The following methods to ‘reduce’ the transition matrix are
available with the optional argument reduceMethod
):
colSums
rowSums
colMeans
rowMeans
NZcolMeans
NZrowMeans
The latter two methods only take into account the non-zero entries in the transition matrix. The default is NZcolMeans.
#create a new raster and set all its values to unity.
r <- raster(nrows=18, ncols=36)
r <- setValues(r,runif(ncell(r),0,1))
#create a Transition object from the raster
tr1 <- transition(r,mean,8)
#> The extent and CRS indicate this raster is a global lat/lon raster. This means that transitions going off of the East or West edges will 'wrap' to the opposite edge.
#> Global lat/lon rasters are not supported under new optimizations for 4 and 8 directions with custom transition functions. Falling back to old method.
#asymmetric
asf <- function(x) max(x) - x[1] + x[2]
tr2 <- transition(r,asf,8, symm=FALSE)
#> The extent and CRS indicate this raster is a global lat/lon raster. This means that transitions going off of the East or West edges will 'wrap' to the opposite edge.
#> Global lat/lon rasters are not supported under new optimizations for 4 and 8 directions with custom transition functions. Falling back to old method.
#create RasterLayer objects
r1 <- raster(tr1)
r2 <- raster(tr2)
r3 <- raster(tr1, "colMeans")