Description Usage Arguments Details Value Author(s) Examples
Create a Transition object from a RasterLayer or RasterBrick object. Transition values are calculated with a user-defined function from the grid values.
1 | transition (x, transitionFunction, directions, ...)
|
x |
|
transitionFunction |
Function to calculate transition values from grid values |
directions |
Directions in which cells are connected (4, 8, 16, or other), see |
... |
additional arguments, see methods 1 and 3 below |
Users may use one of three methods to construct a Transition* object with this function.
1) TransitionLayer
from RasterLayer
transition(x, transisitonFunction, directions, symm)
When a symmetric transition matrix is required, the user should supply a transitionFunction f that obeys f(i,j) = f(j,i) (a commutative function).
The function transition
does no commutativity check.
To obtain an asymmetric transition matrix, a non-commutative function should be supplied and an additional argument ‘symm’ should be set to FALSE.
2) TransitionLayer
from RasterBrick
transition(x, transitionFunction="mahal", directions)
This method serves to summarize several layers of data in a single distance measure. The distance between adjacent cells is the normalized reciprocal of the Mahalanobis distance (mean distance / (mean distance + distance ij).
3) TransitionStack
from RasterLayer
In contrast with the above methods, this method produces resistance matrices by default.
a) Continuous variables - barriers
transition(x, transitionFunction="barriers", directions, symm, intervalBreaks)
This method creates a TransitionStack
with each layer containing a discrete boundary between areas in x
.
Areas are defined by intervals in x
.
The argument intervalBreaks
is a vector of interval breaks corresponding to the values in x
.
If between a pair of cells i and j, min(i,j) < break AND max(i,j) > break, then the value ij in the transition matrix becomes 1.
All other values in the transition matrix remain 0.
The package classInt offers several methods to define intervals.
If symm is changed from the default (TRUE) to "up" or "down", it will give either only the upslope (symm="up") or downslope (symm="down") barriers.
b) Categorical variables - barriers
transition(x, transitionFunction="barriers", directions)
In this case, areas are defined as categories in the input raster.
A raster with a categorical variable can be created with asFactor()
.
The layers of the resulting TransitionStack contain all possible combinations of categories.
Which layer contains the combination of categories i and j out of n categories, can be determined with these formulae:
if symm
is TRUE
: layer(i,j) = n*(j-1) - j*(j-1)/2 + i-j.
if symm
is FALSE
and i>j: layer(i,j) = ((n*(j-1) - j*(j-1)/2 + i-j) * 2) - 1.
if symm
is FALSE
and i<j: layer(i,j) = (n*(j-1) - j*(j-1)/2 + i-j) * 2.
c) Categorical variables - areas
transition(x, transitionFunction="areas", directions)
Here, areas are also a categorical variable (see under 3b). The layers in the resulting TransitionStack represent each one area. Connections between two cells which are each inside the area are set to 1. Connections between a cell inside and a cell outside the area are set to 0.5. Connections between two cells outside the area are set to 0.
Transition object
Jacob van Etten jacobvanetten@yahoo.com
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #Create a new raster and set all its values to unity.
r <- raster(nrows=18, ncols=36)
r <- setValues(r, runif(ncell(r)))
#Create a Transition object from the raster
tr <- transition(r, transitionFunction=mean, directions=4)
tr #the sparse matrix is of class dsCMatrix (symmetric)
#Create an asymmetric transition matrix
#first, an arbitrary non-commutative function
f <- function(x) max(x) - x[1] + x[2]
tr2 <- transition(r, f, 4, symm=FALSE)
tr2 #the sparse matrix is of class dgCMatrix (=asymmetric)
#Barriers - interval breaks
tr3 <- transition(r, "barriers", 8, intervalBreaks=c(0.25, 0.5, 0.75))
nlayers(tr3)
#Barriers - categories
r <- round(r * 2)
r <- asFactor(r)
tr4 <- transition(r, "barriers", 8)
nlayers(tr4)
plot(raster(tr4[[2]]))
#Areas
r <- round(r * 2)
r <- asFactor(r)
tr5 <- transition(r, "areas", 8)
nlayers(tr5)
plot(raster(tr5[[2]]))
|
Loading required package: raster
Loading required package: sp
Loading required package: igraph
Attaching package: 'igraph'
The following object is masked from 'package:raster':
union
The following objects are masked from 'package:stats':
decompose, spectrum
The following object is masked from 'package:base':
union
Loading required package: Matrix
Attaching package: 'gdistance'
The following object is masked from 'package:igraph':
normalize
class : TransitionLayer
dimensions : 18, 36, 648 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
values : conductance
matrix class: dsCMatrix
class : TransitionLayer
dimensions : 18, 36, 648 (nrow, ncol, ncell)
resolution : 10, 10 (x, y)
extent : -180, 180, -90, 90 (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84
values : conductance
matrix class: dgCMatrix
[1] 3
[1] 3
[1] 3
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.