#Create a new raster and set all its values to a random value.
r <- raster(nrows=18, ncols=36)
r <- setValues(r,runif(ncell(r), 0.4, 0.6))
#Create a Transition object from the raster
tr <- transition(r,mean,8)
trC <- geoCorrection(tr, type="c")
#Create two sets of coordinates
sP1 <- SpatialPoints(cbind(-105,55))
sP2 <- SpatialPoints(cbind(105,-55))
#Calculate the shortest path
sPath1 <- shortestPath(tr, sP1, sP2)
sPath2 <- shortestPath(tr, sP1, sP2, output="SpatialLines")
plot(raster(sPath1))
lines(sPath2)
Run the code above in your browser using DataLab