snoops
snoops

Reputation: 37

Get slope between two cells in gdistance

I have created the following Transition Object from a raster containing altitude values of a landscape in R:

wd <- "C:/Users/LG/Dropbox/Random Walk"                                         
setwd(wd)                                                                       

    library(gdistance)
    library(raster)


    r <- raster("altitude.tif")
    altDiff <- function(x){x[2] - x[1]}
    hd <- transition(r, altDiff, 8, symm=FALSE)

    slope <- geoCorrection(hd)

As you can see the function I use to create said objecs is the difference in altitude between two cells, which is then corrected into the slope between cells via the 'geocorrection' function. How can I access the slope between two cells of my choice now ? In order to complete my script I need to get the slope values between a cell of my choice and all eight cells that are adjacent to it. So basically I want to know how I can access the transition values for two cells of my choice? If anybody could help me with this I would really appreciate it. Thanks in advance.

Upvotes: 0

Views: 119

Answers (1)

JacobVanEtten
JacobVanEtten

Reputation: 203

I suggest you read the vignette of the gdistance package, which explains this fully.

To get the slope between cells 1 and 2, you can do:

slope[1,2]

Take a look at the adjacent function in the raster package to get a full list of the 8 adjacent cells.

Upvotes: 1

Related Questions