Le API di OSRM sono disponibili al seguente indirizzo http://project-osrm.org/ http://project-osrm.org/docs/v5.5.1/api/#general-options
Documentazione per un service routing provider onpremise https://github.com/Project-OSRM/osrm-backend per le prove utilizziamo un Demo server https://github.com/Project-OSRM/osrm-backend/wiki/Demo-server
the demo server usage is restricted to reasonable, non-commercial use-cases. Do not exceed 1 request per second. We provide no guarantees wrt. uptime, latency, or data updates https://routing.openstreetmap.de/about.html
Le API di ORS sono disponibili al seguente indirizzo https://openrouteservice.org/
library(leaflet)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.2 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ purrr 1.0.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(tidygeocoder)
library(openrouteservice)
library(httr)
source('config.R')
some_addresses <- tibble::tribble(
~name, ~addr,
"novoli","Via di novoli 26 Firenze",
"sanita", "Via Alderotti 26, Firenze",
)
lonlat <- some_addresses %>%
geocode(addr, long = longitude,lat = latitude , method = 'osm')
Anche OSR dispone di una funzione per il recupero delle coordinate ma è necessario passare un indirizzo per volta
ris_ors <- ors_geocode(query = "Via di novoli 26 Firenze",'IT',api_key = tokenORS)
mapl <- leaflet()%>% addTiles()%>%addMarkers(lng=lonlat$longitude,lat=lonlat$latitude,label='tidygeocode',labelOptions = labelOptions(noHide = T))
mapl
ind1 <- lonlat[1,]
ind2 <- lonlat[2,]
url='https://router.project-osrm.org'
path1=paste0("/route/v1/driving/",ind1$longitude,",",ind1$latitude,";",ind2$longitude,",",ind2$latitude,'?','alternatives=true&geometries=geojson')
con1=GET(url=url,path=path1)
ris1=content(con1)
routes1=ris1$routes[[1]]
routes2=ris1$routes[[2]]
coordr1 <- routes1$geometry$coordinates
coordr2 <- routes2$geometry$coordinates
ind1 <- lonlat[1,]
ind2 <- lonlat[2,]
mapl <- leaflet()%>% addTiles()%>%addMarkers(lng=ind1$longitude,lat=ind1$latitude)%>%addMarkers(lng=ind2$longitude,lat=ind2$latitude)
georoute1 <-as.data.frame(do.call(rbind,coordr1))
lonr1 <- as.numeric(georoute1$V1)
latr1 <- as.numeric(georoute1$V2)
mapl <- mapl%>%addPolylines(lonr1,latr1,label=paste0('OSRM1 distanza km: ',routes1$distance/1000),labelOptions = labelOptions(noHide = T))
georoute2 <-as.data.frame(do.call(rbind,coordr2))
lonr2 <- as.numeric(georoute2$V1)
latr2 <- as.numeric(georoute2$V2)
mapl <- mapl%>%addPolylines(lonr2,latr2,label=paste0('OSRM2 distanza km: ',routes2$distance/1000),labelOptions = labelOptions(noHide = T))
mapl
free and opensource https://openrouteservice.org/
tutti i piani gratuiti ma quelli personali e per organizzazioni con numero di richiesta limitato. Installazione on promise sempre con docker unlimited
Calcolo e rappresentazione della direzione
x <- ors_directions(data.frame(lonlat$longitude,lonlat$latitude),api_key = tokenORS)
distance <- x$features[[1]]$properties$summary$distance/1000
mapl2 <- leaflet()%>%addTiles()%>%addMarkers(lng=lonlat$longitude,lonlat$latitude)
mapl2 <-mapl2%>%
addPopups(lonlat$longitude[1],lonlat$latitude[1], paste0("Distanza in km: ",distance),
options = popupOptions(closeButton = FALSE)
)%>%
addGeoJSON(x, fill=FALSE)%>%
fitBBox(x$bbox)
mapl2
Isocrone a 600 e 300 secondi
res <- ors_isochrones(data.frame(lonlat$longitude,lonlat$latitude), range = 600, output = "sf",api_key = tokenORS)
mapl <- mapl%>%addGeoJSON(res$geometry)
res <- ors_isochrones(data.frame(lonlat$longitude,lonlat$latitude), range = 300, output = "sf",api_key = tokenORS)
mapl <- mapl%>%addGeoJSON(res$geometry,color="red") %>%
fitBBox(x$bbox)
mapl