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))
# introduce spatial gradient
costras[] <- runif(ncell(costras), min = 1, max = 10)
for (i in 1:nrow(costras)) {
costras[i, ] <- costras[i, ] + i
costras[, i] <- costras[, i] + i
}
rstack <- pathdistGen(sf_ob, costras, 100, progressbar = FALSE)
final.raster <- ipdwInterp(sf_ob, rstack, paramlist = c("rnorm.2."), overlapped = TRUE)
plot(final.raster)
plot(sf_ob, add = TRUE)
Run the code above in your browser using DataLab