Topic: Spatial

Topic Description:

Functions for calculating Ripley's K from CTFS R Analytical Tables, many routines for quadrat-based calculations. and calculations of wavelet variance.



File: spatial/slope.r

View File Source Download File No help file available

Function: calc.gradient

Function Description: calc.gradient

Calculate flow using Seibert & McGlynn algorithm. Takes a 3x3 matrix of elevations and works on central point; also requires grid size (usually 20 m) z=matrix(c(c(268.7,275.9,283.2),c(275.9,282.8,290.0),c(283.2,290.0,297)),nrow=3,byrow=TRUE) This calculates the gradient for the 8 triangular facets around the center point, following Seibert & McGlynn The output is a data.frame of direction and slope for the 8 facets, starting with the lower left and moving clockwise

Function Arguments:

ArgumentDefault Value
elev
grid20
elev
grid20

Function Source:

calc.gradient=function(elev,grid=20)
{
elev.ctr=elev[2,2]
elev.corner=c(elev[1,1],elev[1,3],elev[3,3],elev[3,1])
elev.side=c(elev[2,1],elev[2,3],elev[2,3],elev[1,2])

x.ctr=y.ctr=grid
x.corner=c(0,0,2*grid,2*grid)
y.corner=c(0,2*grid,2*grid,0)
x.side=c(0,grid,2*grid,grid)
y.side=c(grid,2*grid,grid,0)
# browser()

corner=side=matrix(ncol=2,nrow=4)

for(i in 1:4)
{
z1=elev.corner[i]-elev.ctr
z2=elev.side[i]-elev.ctr

x1=(x.corner[i]-x.ctr)
x2=(x.side[i]-x.ctr)

y1=(y.corner[i]-y.ctr)
y2=(y.side[i]-y.ctr)

corner[i,]=calc.directionslope(z1,z2,x1,x2,y1,y2)
}

for(i in 1:4)
{
z2=elev.corner[i]-elev.ctr
z1=elev.side[i]-elev.ctr

x2=x.corner[i]-x.ctr
x1=x.side[i]-x.ctr

y2=y.corner[i]-y.ctr
y1=y.side[i]-y.ctr

side[i,]=calc.directionslope(z1,z2,x1,x2,y1,y2)
}

result=matrix(ncol=2,nrow=8)
colnames(result)=c("direction","slope")
result[c(1,3,5,7),]=corner
result[c(2,4,6,8),]=side

return(data.frame(result))
}