Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with viaroute example #141

Closed
Robinlovelace opened this issue Nov 15, 2016 · 8 comments
Closed

Issue with viaroute example #141

Robinlovelace opened this issue Nov 15, 2016 · 8 comments
Labels

Comments

@Robinlovelace
Copy link
Member

This is what I get when running the viaroute example:

 exroutes <- viaroute(viapoints=list(data.frame(x=c(-33.5,-33.6,-33.7),y=c(150,150.1,150.2))))
  r <- viaroute2sldf(exroutes)
Error in data.frame(routenum = i, routedesc = rep(x$routes$legs[[i]]$summary,  : 
  arguments imply differing number of rows: 1, 16, 8, 0

The other example works fine though. Any ideas @richardellison?

@richardellison
Copy link
Collaborator

I'll have a look, the error implies that the number of routes doesn't match the summary information which seems rather odd (and I'm sure this example worked when I tried it a few weeks ago).

@Robinlovelace
Copy link
Member Author

Thanks for the fix - no longer errors but I get some strange warnings and the output looks strange:

> exroutes <- viaroute(viapoints=list(data.frame(x=c(-33.5,-33.6,-33.7),y=c(150,150.1,150.2))))
> r <- viaroute2sldf(exroutes)
Warning messages:
1: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
2: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
3: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
4: In bind_rows_(x, .id) : Unequal factor levels: coercing to character
plot(r)

screenshot from 2016-11-20 18-44-23

@Robinlovelace
Copy link
Member Author

Compared with this from the osrm package:

install.packages("osrm")
library(osrm)
r_osrm <- osrmTrip(data.frame(i = 1:3,x=c(150,150.1,150.2),y=c(-33.5,-33.6,-33.7)))
plot(r_osrm[[1]]$trip)

screenshot from 2016-11-20 18-54-45

@Robinlovelace
Copy link
Member Author

Also this seems to generate an error with the stplanr implementation:

origin = tmap::geocode_OSM("London")
destination = tmap::geocode_OSM("Leeds")
od_df = rbind(origin$coords, destination$coords)
exroutes <- viaroute(viapoints = list(od_df))
r <- viaroute2sldf(exroutes)
Error in data.frame(routenum = i, legnum = j, routedesc = rep(x$routes$legs[[i]]$summary[j],  : 
  arguments imply differing number of rows: 1, 2, 0

Interestingly this also seems to fail with osrm:

ro = osrmRoute(origin, destination)
osrmRoute function returns an error: 
Error: URL string malformed close to position 31: "73, 51"

@Robinlovelace
Copy link
Member Author

Update: it works with osrm: riatelab/osrm#17

@richardellison
Copy link
Collaborator

Reopening, seeing the same thing. I'll have another look.

@Robinlovelace
Copy link
Member Author

Any update on this @richardellison? Thinking better to fix bugs before adding new features and improving performance.

@richardellison
Copy link
Collaborator

This has been fixed in #161. The following now returns the correct geometries.

exroutes <- viaroute(viapoints=list(data.frame(x=c(-33.5,-33.6,-33.7),y=c(150,150.1,150.2))))
r <- viaroute2sldf(exroutes)

image

You will notice that this is different from the result returned by the osrm package. This is because the "osrm" package calculates the individual routes between each pair of coordinates while this implementation uses the coordinates as waypoints on a single route. To return the same result as the "osrm" package you can run the following:

exroutes2 <- viaroute(viapoints=list(
    data.frame(x=c(-33.5,-33.7),y=c(150,150.2)),
    data.frame(x=c(-33.6,-33.7),y=c(150.1,150.2))
))
r2 <- viaroute2sldf(exroutes2)

image

Robinlovelace added a commit that referenced this issue Dec 9, 2016
Correct problems with viaroute2sldf when routes contain multiple legs. Fixes #141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants