# Load data
data("com")
# Travel path between points
routeGeom <- osrmViarouteGeom(src = com[1, c("comm_id", "lat","lon")],
dst = com[15, c("comm_id", "lat","lon")])
# Display the path
plot(com[c(1,15),3:4], asp =1, col = "red", pch = 20, cex = 1.5)
points(routeGeom[,2:1], type = "l", lty = 2)
text(com[c(1,15),3:4], labels = com[c(1,15),2], pos = 2)
# Travel path between points - output a SpatialLinesDataFrame
routeGeom2 <- osrmViarouteGeom(src=c("Bethune", 50.5199, 2.64781),
dst = c("Cassel", 50.80016, 2.486388),
sp = TRUE)
class(routeGeom2)
# Display the path
plot(com[c(1,16),3:4], asp =1, col = "red", pch = 20, cex = 1.5)
plot(routeGeom2, lty = 2, add=TRUE)
text(com[c(1,16),3:4], labels = com[c(1,16),2], pos = 2)
Run the code above in your browser using DataLab