Dear Jan Hendrik,

I made an example that is equivalent to the example in the GRASS r.cost help file (http://grass.fbk.eu/gdp/html_grass63/r.drain.html):

library(gdistance)

r <- raster(nrows=6, ncols=7, xmn=0, xmx=7, ymn=0, ymx=6, crs="+proj=utm +units=m")
 
r[] <- c(2, 2, 1, 1, 5, 5, 5,
         2, 2, 8, 8, 5, 2, 1,
         7, 1, 1, 8, 2, 2, 2,
         8, 7, 8, 8, 8, 8, 5,
         8, 8, 1, 1, 5, 3, 9,
         8, 1, 1, 2, 5, 3, 9)

T <- transition(r, function(x) 1/mean(x), 8) 
# 1/mean: reciprocal to get permeability instead of friction
T <- geoCorrection(T)

c1 <- c(5.5,1.5) 
c2 <- c(1.5,5.5)

A <- accCost(T, c1)
plot(A)
text(A) #rounded values
sPath2 <- shortestPath(T, c1, c2, output="SpatialLines")
lines(sPath2)

#alternatively
sPath1 <- shortestPath(T, c1, c2)
plot(raster(sPath1))

I hope this helps.

Best wishes,

Jacob.



________________________________
From: Jan Hendrik Blanke <jan.blanke@gmx.de>
To: r-sig-geo@r-project.org
Sent: Thursday, 10 November 2011, 16:37
Subject: [R-sig-Geo] gdistance, least cost path in R

Hello together,

I would like to conduct a least cost path analysis in R that would deliver the same results than GRASS GIS (r.cost followed by r.drain) or ArcGIS (Cost Distance followed by Cost Path, both Spatial Analyst). For that purpose, I created a raster with  cost values ranging from 1 to 8; the starting and stop points are from the class SpatialPointsDataFrame.

I used the package gdistance now to calculate the path with the least costs from source to destination but could not manage to get the same results than GRASS GIS and ArcGIS. Gdistance uses a transition layer instead of an accumulative cost grid. For the latter one an iterative process is used that begins with the source cells. The transition layer instead is calculated by a transition function that calculates transition values from grid values (e.g. mean).

I guess the problem lies in the creation of the transition layer with transitionFunction. I am not sure which function I would need to use. In addition, I am wondering how the transition layer could be similar to the accumulative cost grid as the transition layer does not calculate the values starting from a source cell.

I would really appreciate if you could give me any hints on how to achieve the same results in R. Thank you very much for your efforts.

Kind regards,

Jan 
--

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
	[[alternative HTML version deleted]]

