# Load data
data("com")
# Travel path between points
routeGeom <- osrmViarouteGeom(xo = com[1,"lon"], yo = com[1,"lat"],
xd = com[15,"lon"], yd = com[15,"lat"])
# 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(xo = com[1,"lon"], yo = com[1,"lat"],
xd = com[16,"lon"], yd = com[16,"lat"],
sp=TRUE,
ido = com[1,"comm_id"],
idd = com[16,"comm_id"])
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