library(sf)
sf_ob <- data.frame(rnorm(2))
xy <- data.frame(x = c(4, 2), y = c(8, 4))
sf_ob <- st_as_sf(cbind(sf_ob, xy), coords = c("x", "y"))
m <- matrix(NA, 10, 10)
costras <- raster(m, xmn = 0, xmx = ncol(m), ymn = 0, ymx = nrow(m))
costras[] <- runif(ncell(costras), min = 1, max = 10)
# introduce spatial gradient
for (i in 1:nrow(costras)) {
costras[i, ] <- costras[i, ] + i
costras[, i] <- costras[, i] + i
}
rstack <- pathdistGen(sf_ob, costras, 100, progressbar = FALSE)
Run the code above in your browser using DataLab