<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#333333" bgcolor="#FFFFFF">
<p>This works for me (`f` is a data.frame of X,Y origin locations,
`t` is a data.frame of X,Y destinations):</p>
<p><tt>osrm_api <- function(f, t, key=NULL) {</tt><tt><br>
</tt><tt><br>
</tt><tt> url <-
<a class="moz-txt-link-rfc2396E" href="https://router.project-osrm.org/table/v1/driving/">"https://router.project-osrm.org/table/v1/driving/"</a></tt><tt><br>
</tt><tt> url <- paste0(url,</tt><tt><br>
</tt><tt> paste(f$X, f$Y, sep=",", collapse=";"), ";",
paste(t$X, t$Y, sep=",", collapse=";"))</tt><tt><br>
</tt><tt> out <- GET(url,</tt><tt><br>
</tt><tt> query=list(</tt><tt><br>
</tt><tt> sources=paste(1:nrow(f)-1, collapse=";"),</tt><tt><br>
</tt><tt> destinations=paste(nrow(f):(nrow(f)+nrow(t)-1),
collapse=";")))</tt><tt><br>
</tt><tt> out <- try(fromJSON(content(out, as="text"),
flatten=TRUE))<br>
return(out)<br>
</tt></p>
<p><tt>}</tt><br>
</p>
<br>
<div class="moz-cite-prefix">On 11/07/2017 08:27 AM, Shruti Tripathi
wrote:<br>
</div>
<blockquote type="cite"
cite="mid:CAAMejQwpCTqyZL_VFCKraUbx6J0f-8mJi5fi_Lhqn9c2uYfRpQ@mail.gmail.com">
<pre wrap="">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
<a class="moz-txt-link-abbreviated" href="mailto:R-sig-Geo@r-project.org">R-sig-Geo@r-project.org</a>
<a class="moz-txt-link-freetext" href="https://stat.ethz.ch/mailman/listinfo/r-sig-geo">https://stat.ethz.ch/mailman/listinfo/r-sig-geo</a>
</pre>
</blockquote>
<br>
</body>
</html>