Comments (6)
Hello Robin,
In fact src
and dst
can take vectors, but they expect a vector with an identifier and coordinates (something like c("ID", "13.41", "52.50")
). I felt it was useful to keep track of the source and destination identifiers when using routes created with osrmRoute()
.
library(osrm)
#> Data: (c) OpenStreetMap contributors, ODbL 1.0 - http://www.openstreetmap.org/copyright
#> Routing: OSRM - http://project-osrm.org/
library(sf)
#> Linking to GEOS 3.7.1, GDAL 2.4.0, PROJ 5.2.0
options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")
route <- osrmRoute(src = c("A", 13.41299, 52.5029),
dst = c("B", 13.45456, 52.59265),
returnclass = "sf")
plot(route)
data("berlin")
s <- c(1:44,46:100)
list_out <- lapply(s, function(i){osrmRoute(src = apotheke.df[45,], dst = apotheke.df[i, ], returnclass = "sf")})
routes_osrm <- do.call(rbind, list_out)
routes_osrm <- routes_osrm[order(-routes_osrm$duration),]
plot(routes_osrm["duration"])
Created on 2019-09-20 by the reprex package (v0.3.0)
If needed I can add a special case when no identifiers are given (length(src) == 2
) and use a default id (something like "src").
from osrm.
If needed I can add a special case when no identifiers are given (length(src) == 2) and use a default id (something like "src").
I think that would be a good solution and reduce the requirement input data. I understand why it was failing now, and understand why keeping the id could be important. Many thanks for quick reply!
from osrm.
@Robinlovelace
The last few commits should allow lon/lat vectors as input for osrmRoute()
.
I have also added a loc
arg to allow the computation of routes with via points.
Don't hesitate to tell me if other changes could ease the use of the package.
from osrm.
Great fix @rCarto, many thanks!
I confirm that it works, the reprex below now works (most other routing apis use c(lon, lat)
making this easier).
remotes::install_github("rCarto/osrm")
library(osrm)
library(stplanr)
options(osrm.server = "http://0.0.0.0:5000/", osrm.profile = "driving")
l = pct::wight_lines_30
p = line2points(l)
r = osrm::osrmRoute(src = p[1,],
dst = p[2,],
returnclass = "sf")
plot(r)
route_osrm2 = function(l) {
p = line2points(l)
s = (1:nrow(l)) * 2 - 1
list_out = lapply(s, function(i)
osrm::osrmRoute(
sf::st_coordinates(p[i,])[, 1:2],
dst = sf::st_coordinates(p[i + ,])[, 1:2],
returnclass = "sf"
))
do.call(rbind, list_out)
}
routes_osrm = route_osrm2(l)
rnet_osrm = overline2(routes_osrm, "duration")
plot(rnet_osrm)
mapview::mapview(rnet_osrm)
One question, how do I make the separate routes follow the same geometries?
overview = "full"
is my guess, not sure if that's the same as FALSE
...
A solution for ropensci/stplanr#340 is close, any feedback on that, welcome.
from osrm.
overview="full"
will give you what you need. overview=FALSE
will return only a vector of time and distance.
ropensci/stplanr#340 and ropensci/stplanr#338 seem fine to me.
from osrm.
Many thanks! Experimenting with local routing on sfNetwork
objects at the moment but I guess OSRM is better for most real-world situations. Looking forward to using it to help build an evidence base for a more sustainable world!
from osrm.
Related Issues (20)
- Substantial Scholarly Effort HOT 1
- no contributing guidelines
- Typo `osrmTrip` example
- osrmRoute argument order HOT 1
- Define 'isochrones' HOT 1
- Difference between `osrmRoute` and `osrmTrip`
- Distance between multiple pairs of points? HOT 1
- How can I remove alternate routes when using osrm package in leaflet(r)? HOT 1
- Improve error handling osrmIsochrone(): out of bounds
- Improve error handling `osrmIsochrone()`: character vector of location HOT 1
- Improve error handling `osrmIsochrone()`: handle empty isochrones
- Improve documentation `osrmIsochrone()`: `breaks` argument
- Define "isometric" and "isodistance"
- Speed parameter HOT 3
- Stop osrm "connecting" to the network via certain types of roads HOT 6
- Problem with input data and osrmTrip() HOT 3
- curl::curl_fetch_memory(utils::URLencode(url) => connection was reset HOT 4
- osrmIsochrone(): 'loc' is too far from the OSRM network but loc is not too far... HOT 9
- Error in `osrmTrip()` when location coordinates are close to each other and/or not on roads HOT 2
- pairwise distance matrix from OSRM? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from osrm.