我想知道将地形纳入 R 中相关随机游走的可能性有哪些。我有研究区域的数字高程模型 (DEM)。我想在我的随机行走中避开陡峭斜坡的区域。
walk <- function(x0, y0, head0, n, parameterMu, parameterRho, parameterMean, parameterSd)
{
# Get nr of individuals, call it k
k = length(x0)
# Create list to hold data
all.paths <- list()
for (j in 1:k)
{
# Create structure to hold data
steps <- data.frame(matrix(0,n,6))
colnames(steps) <- c("id","x", "y", "steplength", "heading", "turningangle")
# Insert the id, starting location and heading
steps[,"id"] = j
steps[1,"x"] = x0[j]
steps[1,"y"] = y0[j]
steps[1,"heading"] = head0[j]
# Simulate steps
for(i in 2:n)
{
# Draw step length and turning angle, compute heading
steplength = rnorm(n = 1, mean = parameterMean, sd = parameterSd)
turningangle = as.numeric(rwrappedcauchy(n = 1, mu = parameterMu, rho = parameterRho))
newbearing = as.numeric(circular(steps[i-1,"heading"]) + circular(turningangle)) %% (2*pi)
# Get new location
next.xy <- movement(x0=steps[i-1,"x"], y0=steps[i-1,"y"], step=steplength, heading=newbearing)
# Store output (xy on row i, steplength/heading on row i-1)
steps[i,"x"] <- next.xy[1,"x"]
steps[i,"y"] <- next.xy[1,"y"]
steps[i,"steplength"] <- next.xy[1,"step"]
steps[i,"heading"] <- newbearing
steps[i,"turningangle"] <- turningangle
# Store trajectory in list
all.paths[[j]] <- steps
}
# Return output
return(all.paths)
}
运动功能:
movement <- function(x0, y0, step, heading)
{
x_new <- x0 + sin(heading)*step
y_new <- y0 + cos(heading)*step
move.temp <- data.frame(x = x_new,
y = y_new,
step = step,
head = heading)
return(move.temp)
}