library(tidyverse)
library(sf)
library(mapview)
library(stplanr)
library(OpenStreetMap)
sfd =
tribble(~lat,~lon,~location,
36.075411, 136.212213,"福井大学",
36.062244, 136.223214, "福井駅") %>%
st_as_sf(coords = c("lon", "lat"), crs = 6668)
sf_line =
sfd %>%
st_combine() %>%
st_cast("LINESTRING") %>%
st_sf(a = 1)
line2route(sf_line, "route_osrm") %>%
mapview()
library(ggspatial)
sf_route = line2route(sf_line, "route_osrm")
ggplot(sf_route) +
annotation_map_tile(zoomin = 0) +
geom_sf()
upperLeft = st_bbox(sf_route) %>% as.vector() %>% .[c(2, 1)]
lowerRight = st_bbox(sf_route) %>% as.vector() %>% .[c(4, 3)]
osmap = OpenStreetMap::openmap(upperLeft = upperLeft,
lowerRight = lowerRight,
type = "stamen-toner",
mergeTiles = T)
osmaplocation = OpenStreetMap::openproj(osmap, st_crs(sfd)$proj4string)
autoplot(osmaplocation) +
geom_path(data =
st_coordinates(sf_route)[,1:2] %>%
as.data.frame() %>%
`colnames<-`(c("x", "y")),
color="blue", size = 3)