Hi everyone,

I'm trying to utilize the gdistance package to perform a least cost
analysis on elevation change. I'd like to find the cost of shortest path
that changes as little elvation as possible.

If it helps, think of it as someone trying carry a injured hiker on
a stretcher, flat is the way to go.

I've previously attempted to use the terrain "slope" function to build the
transition matrix, but the example below uses the code and structure
provided by the gdistance vignette. I hope it is fully reproducible. My
main concerns 1) Despite usually abs(), i get different paths depending on
origin/destination 2) The conductance values do not line up (in my crude
approximation)

require(gdistance)
#Create a Elev raster of the volcano

DEM<-raster(system.file("external/maungawhau.grd",package = "gdistance"))

#Using the method  given in the gdistance vignette?
#Is this repeating for all 8 cells, difference in all 8 cells, does it take
the mean? Is it applying this calculation to all pairwise adjacent cells
(8)?

hd1<-transition(DEM,function(x){1/abs(x[2] - x[1])},8)

#Incorporate distance across cell centers
slope1 <- geoCorrection(hd1)

#Define some random points
A <- cbind(2667670, 6479000)

B <- cbind(2667800, 6479400)

pts<-rbind(A,B)

#Lets look at it visually
plot(raster(slope1))
points(pts,col='red',pch=16)

plot(DEM)
BA<-shortestPath(slope1,B,A,"SpatialLines")
AB<-shortestPath(slope1,A,B,"SpatialLines")
lines(BA)
lines(AB)
#This is the first red flag, i've set an the transition matrix as an
absolute value, but i still get different shortest paths from AB and BA


#Get the elevation path from the shortest profile, this should roughly
relate to the diff in elevation along the path, given not infinite sampling
along the line
shortestProfile1<-unlist(extract(DEM,AB))
shortestProfile2<-unlist(extract(DEM,BA))

par(mfrow=c(1,2))
plot(shortestProfile1,type='l')
plot(shortestProfile2,type='l')


#Get the sum of the differences for the elevation profiles on the shortest
paths, a very approximate measure
sum(abs(diff(shortestProfile1, 1)))
sum(abs(diff(shortestProfile2, 1)))

#If the cell size is 10m, then  the conductance/10 should roughly be delta
elevation, ignoring diagonals have a longer distance?
costDistance(slope1,pts)/10

#This doesn't really seem to match the elevation profile, is there anyway
for me to get actual elevation to check the validity of the path?

As always, I appreciate the help

Ben Weinstein
-- 
Ben Weinstein
Graduate Student
Ecology and Evolution
Stony Brook University

http://life.bio.sunysb.edu/~bweinste/index.html

-- 
Ben Weinstein
Graduate Student
Ecology and Evolution
Stony Brook University

<http://life.bio.sunysb.edu/~bweinste/index.html>
<http://life.bio.sunysb.edu/~bweinste/index.html>
http://life.bio.sunysb.edu/~bweinste/index.html

	[[alternative HTML version deleted]]

