I would like your help with the route_local function of the stplanr package (https://cran.r-project.org/web/packages/stplanr/stplanr.pdf), which is on page 89.
You ma
Try this. To adapt the example to your case you have to convert the coordinate system of the roads
to the points
shapefile (or the other way around):
library(geosphere)
library(sf)
library(stplanr)
roads <- st_read("Example/Roads/Roads.shp")
points <- st_read("Example/Points/Points.shp")
# Convert roads to coordinate system of points
roads_trf <- st_transform(roads, st_crs(points))
# Convert to points to SpatialPointsDataframe
points_sp <- as(points, "Spatial")
from <- c(-49.95058, -24.77502) # Feature 1
to <- c(-49.91084, -24.75200) # Feature 9
p <- SpatialLinesNetwork(roads_trf, uselonglat = FALSE, tolerance = 0)
r <- route_local(p, from, to)
plot(p)
plot(r$geometry, add = TRUE, col = "red", lwd = 5)
plot(points_sp[c(3, 4), ], add = TRUE)
r2 <- route_local(sln = p, points[3, ], points[4, ])
plot(r2$geometry, add = TRUE, col = "blue", lwd = 3)