Giter VIP home page Giter VIP logo

Comments (6)

rCarto avatar rCarto commented on June 3, 2024

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.

Robinlovelace avatar Robinlovelace commented on June 3, 2024

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.

rCarto avatar rCarto commented on June 3, 2024

@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.

Robinlovelace avatar Robinlovelace commented on June 3, 2024

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?

image

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.

rCarto avatar rCarto commented on June 3, 2024

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.

Robinlovelace avatar Robinlovelace commented on June 3, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.