CLUSexample <- prepExData(CLUSexample)
# Deprecated
# getDistFromSource(CLUSexample$roads, 5, 2)
# Use terra::distance instead
terra::distance(CLUSexample$roads, target = 0)
# \donttest{
library(sf)
library(terra)
#make example roads from scratch
rds <- data.frame(x = 1:1000/100, y = cos(1:1000/100)) %>%
st_as_sf(coords = c("x", "y")) %>%
st_union() %>%
st_cast("LINESTRING")
rds_rast <- rasterize(vect(rds),
rast(nrows = 50, ncols = 50,
xmin = 0, xmax = 10,
ymin = -5, ymax = 5),
touches = TRUE)
terra::distance(rds_rast)
# or straight from the line
terra::distance(rds_rast, terra::vect(rds %>% st_set_crs(st_crs(rds_rast))))
# }
Run the code above in your browser using DataLab