[R-sig-Geo] Question about gdistance

Matías Guzmán Naranjo mguzm@nn89 @end|ng |rom gm@||@com
Wed Mar 23 21:32:28 CET 2022

Dear all,

I am trying to build topographic distances with gdistance (following the
method used in the topoDistance package). I am struggling with one issue
I want to get topo distances between points in a raster but forcing the
paths taken to prefer waterways when possible.

Getting the actual paths is relatively straightforward, I create a surface
with the same approach as here
<https://github.com/ianjwang/topoDistance/blob/master/R/topoSurface.R> but

h.dist <- gdistance::transition(DEM, transitionFunction = function(x){1},
directions = directions, symm = TRUE)


h.dist <- gdistance::transition(DEM, transitionFunction = function(x){
                          if((x[1]==0) & (x[2]==0)) 2
                          else 1
                      }, directions = 8, symm = TRUE)

(assuming 0 represents waterways in the DEM). I can then use the surface to
compute the paths and the distances.

That way, the path taken tries to take a waterway whenever possible.
However, this affects the actual distance that is computed. If I change the
'2' to, say, '3', the paths are identical but the distances become smaller.

Is there a way to solve this issue?

Thanks a lot!

	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list