# [R-sig-Geo] gdistance -- How to combine transition Layers?

Mon Sep 26 17:37:58 CEST 2011

```Dear all,

This is my first post here, so I thank you in advance for your help.

My goal is to calculate the cost of traveling (friction) between two
geographical points, given underlying "friction" rasters.

Suppose for example that my data is composed of two rasters, one
binary for roads (a given cell has a road or not), and another,
continuous, for, say, altitude. Using the "gdistance" package, one can
calculate a transition function between cells. The resulting
transitionLayers can be combined by addition or multiplication (see
http://cran.r-project.org/web/packages/gdistance/vignettes/gdistance-vignette.pdf).

However, what I would need is to combine them using some kind of max
function. In other words, the transition to use would be roads if
there is one, otherwise by foot (in which case the altitude transition
layer should be used). Here is a working example that shows where I
get stuck:

require(raster)
require(gdistance)

#Create sample rasters
altitude <- raster(nrows=10, ncols=10)
altitude <- setValues(altitude, runif(10*10))        ; plot(altitude)

#Define transition layers
x[1]*x[2]*60, 8)  #  driving at 60km/h is possible iff both cells are