help needed regarding package OSRM

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

help needed regarding package OSRM

Shruti Tripathi
Hi,

We want to compute the distances between two matrices of  points in (long,
lat)
This is how, as per the manual distance is calculated between two points:

route <- osrmRoute(src = com[1, c("comm_id", "lon","lat")],
dst = com[15, c("comm_id", "lon","lat")])

How would I compute the same for a matrix of source and destination, for
example

route <- osrmRoute(src = com[1:10, c("comm_id", "lon","lat")],
dst = com[11:20, c("comm_id", "lon","lat")])

how do i do this???

Regards
Shruti

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: help needed regarding package OSRM

Bacou, Melanie

This works for me (`f` is a data.frame of X,Y origin locations, `t` is a data.frame of X,Y destinations):

osrm_api <- function(f, t, key=NULL) {

  url <- "https://router.project-osrm.org/table/v1/driving/"
  url <- paste0(url,
    paste(f$X, f$Y, sep=",", collapse=";"), ";", paste(t$X, t$Y, sep=",", collapse=";"))
  out <- GET(url,
    query=list(
      sources=paste(1:nrow(f)-1, collapse=";"),
      destinations=paste(nrow(f):(nrow(f)+nrow(t)-1), collapse=";")))
  out <- try(fromJSON(content(out, as="text"), flatten=TRUE))
  return(out)

}


On 11/07/2017 08:27 AM, Shruti Tripathi wrote:
Hi,

We want to compute the distances between two matrices of  points in (long,
lat)
This is how, as per the manual distance is calculated between two points:

route <- osrmRoute(src = com[1, c("comm_id", "lon","lat")],
dst = com[15, c("comm_id", "lon","lat")])

How would I compute the same for a matrix of source and destination, for
example

route <- osrmRoute(src = com[1:10, c("comm_id", "lon","lat")],
dst = com[11:20, c("comm_id", "lon","lat")])

how do i do this???

Regards
Shruti

	[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo