lcmw: Least Cost Moving Windows Calculation

Description Usage Arguments Details Value Author(s) Examples

Description

This is a moving window that for each cell returns the minimum 'cost' based on surrounding data cells and some dispersal distance cost.

Usage

1
lcmw(mat, mw, mnc)

Arguments

mat

a matrix of values that can be based on a raster dataset. Lower values should represent lower cost. The matrix can be a raster of class 'asc' (adehabitat package), 'RasterLayer' (raster package) or 'SpatialGridDataFrame' (sp package)

mw

a distance-cost matrix to be applied to each cell of 'mat'. This matrix can be dispersal costs. Lower values should represent lower cost.

mnc

an integer value representing the radius for 'mw' in number of cells.

Details

This method moves over the matrix of values, summing the moving window cost mw and the matrix mat, returning the minimum cost value. This was created to estimate the least cost path through time for all cells in a matrix (see example).

Value

A matrix of values of the same dimensions and class as input mat

Author(s)

Jeremy VanDerWal jjvanderwal@gmail.com

Examples

 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 simple object of class 'asc'
tasc = as.asc(matrix(1:100,nr=10,nc=10)); print(tasc)

#show the input matrix
print(tasc[1:10,1:10])

#vary the moving windows

###no cost window of 2 cell radius
tcost = matrix(0,nr=5,nc=5); print(tcost)
out = lcmw(tasc, tcost, 2); print(out[1:10,1:10])

###no cost with a circular radius of 2
tcost = matrix(NA,nr=5,nc=5)
#populate the distances
for (y in 1:5){
    for (x in 1:5){
        tcost[y,x] = sqrt((3-y)^2 + (3-x)^2)
    }
}

#remove distance values > max.num.cells
tcost[which(tcost>2)]=NA

#no cost matrix
tcost1 = tcost; tcost1[is.finite(tcost1)]=1; print(tcost1)
out = lcmw(tasc, tcost1, 2); print(out[1:10,1:10])

#linear cost
tcost = tcost/2; print(tcost)
out = lcmw(tasc, tcost, 2); print(out[1:10,1:10])

jjvanderwal/SDMTools documentation built on May 19, 2019, 11:40 a.m.