Routing back on the same way

This is probably a stupid question…

Suppose I want to route from point A to B and back to C where C is on the route from A to B - the returned rout with all algos I tried basically goes from A via C to B - which can be fine, but what I really want is the total distance (and route from A via B to C - how can I call GH to do that?

What is the use case here? This seems to me not very common :slight_smile:

You can calculate a route from A to B or a route from A to B to C, but in order to go from A to B and back to some point on this route will require that you use a more low level API. So calculate the path from A to B, then call path.calcEdges, pick the point C of your choice, then route from B to C and call PathMerger. See the ‘low level API’ and ‘routing’ documentation.

Suppose a cross country skiing network which you typically don’t run only once, i.e. you’d loop around this part, then back to some junction, make another loop etc. At the end, you might want to know how long you actually ran (and what altitude you covered) - that’s the usecase I covered with Routino so far

But do you know these locations before you do the query? Will adding these three or four points to the GHRequest help?

Those points get created by clicking on the map (i.e. you have to approximately know/remember where you actually went or want to go on a tour), then I pass them on to the router.

Same goes for planning a mountain hike or something similar - often you go back (at least partially) where you went uphill in that case. The total distance of the route (or a GPX of it etc.) is of interest of course.

You can just specify multiple points: https://graphhopper.com/maps/?point=44.792069%2C11.164169&point=44.813201%2C11.214123&point=44.80157%2C11.179705 and the same for the Java API:

req = new GHRequest();
// call multiple times:
req.addPoint(..)

This is what I do anyway, i.e. I pass point A, B and C (which is the order in which I intend to travel). The route I get in return is however A->C->B (because C is actually on the route between A and B)

Adding A, B, X will produce a different route than A, X, B. Also you can do A, X, B, X … otherwise I fear I’ve still not understood your use case

I’m afraid this is not what I observe:

First route, A to B:

2016-09-27 08:55:20,978 [qtp1508269304-15] INFO com.graphhopper.http.GHBaseServlet - point=47.660647256808595,11.886005401611326&point=47.6205125920641,11.891155242919922&instructions=true&type=json&key=undefined&weighting=shortest&vehicle=foot 127.0.0.1 de_DE Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 [47.660647256808595,11.886005401611326, 47.6205125920641,11.891155242919922], took:0.009775207, , shortest, foot, alternatives: 1, distance0: 5174.22888327678, time0: 62min, points0: 120, debugInfo: idLookup:0.001906773s; , algoInit:2.17955E-4s, dijkstrabiCH-routing:0.005917761s, extract time:1.7553E-4;, algoInit:2.17955E-4s, dijkstrabiCH-routing:0.005917761s, extract time:1.7553E-4, simplify (132->120)

Second route, A to B to C: (C is on the route between A and B):

2016-09-27 08:55:51,361 [qtp1508269304-14] INFO com.graphhopper.http.GHBaseServlet - point=47.660647256808595,11.886005401611326&point=47.64110425422311,11.896305084228516&point=47.6205125920641,11.891155242919922&instructions=true&type=json&key=undefined&weighting=shortest&vehicle=foot 127.0.0.1 de_DE Mozilla/5.0 (Windows NT 6.1; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0 [47.660647256808595,11.886005401611326, 47.64110425422311,11.896305084228516, 47.6205125920641,11.891155242919922], took:0.005373121, , shortest, foot, alternatives: 1, distance0: 5174.226807326266, time0: 62min, points0: 122, debugInfo: idLookup:0.001483086s; , algoInit:1.95731E-4s, dijkstrabiCH-routing:7.00446E-4s, extract time:7.8652E-5;, algoInit:1.74575E-4s, dijkstrabiCH-routing:5.9907E-4s, extract time:7.8786E-5;, algoInit:1.95731E-4s, dijkstrabiCH-routing:7.00446E-4s, extract time:7.8652E-5;, algoInit:1.74575E-4s, dijkstrabiCH-routing:5.9907E-4s, extract time:7.8786E-5, simplify (134->122)

-> the distance is the same for both routes, expectation would be that the distance of the leg from B “back to” C would be added to that of the distance between A and B (as well as the resulting point list etc.)

I have not seen such behavior, checking also the site:

A to B is 263m:
https://graphhopper.com/maps/?point=52.523921%2C13.361167&point=52.524995%2C13.364632&locale=en-US&vehicle=car&weighting=fastest&elevation=true&use_miles=false&layer=Omniscale

A to B to C (C is on the route between A and B) is 385m:
https://graphhopper.com/maps/?point=52.523921%2C13.361167&point=52.524985%2C13.364648&point=52.524499%2C13.363039&locale=en-US&vehicle=car&weighting=fastest&elevation=true&use_miles=false&layer=Omniscale

Well, I’m running my own GH instance (0.6 at this time) so chances are this is some configuration problem on my end…

It is no configuration problem I think. The point C you are using is at the third position (as you can easily see in your own logs), try
point=47.660647%2C11.886005&point=47.620513%2C11.891155&point=47.641104%2C11.896305
instead

:disappointed_relieved: right - I should have seen that, so it’s the leaflet plugin (or my usage of it) which is the culprit. sorry and thanks for the eye opener!

Just for reference (in case someone stumbles across this later), the leaflet GH plugin I’m using is http://www.liedman.net/leaflet-routing-machine/ and the “real” issue with it is https://github.com/perliedman/leaflet-routing-machine/issues/305

1 Like