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
Add U-Turns #1073
Add U-Turns #1073
Conversation
A heading per instruction is not a bad idea as e.g. the very first continue after every via or start point could need something like "go north" which the client then could at least create on its own. But before exposing this into the public JSON response lets think twice or more about the "if" and "how" :)
What do you mean here? With a via point it is not that unlikely (?) |
Yes exactly, the typical case would be a via-point. But GrapHopper calculates the instructions independently for every path between waypoints (see PathMerger). So Having a route a->b->c, GH calculates instructions for a->b and b->c. Therefore, it is not easy to create a u-turn instruction at b. One solution could be to pass some contextual information about the last path (a->b) into the creation of the next path (b->c). Another idea could be to merge the instructions by adding a u-turn if necessary. This could be done by adding the orientation for the last part of the edge in every last instruction and the orientation for every first instruction, so the merger could see if they are opposite and add a u-turn. If they are 90° the merger could add a regular turn instruction (might be the case when placing a waypoint on an intersection.
Yes, so I only added it for the first instruction after a waypoint, but we could also do this for every instruction (not sure if that would be needed). |
After thinking about this a bit more, we could also create a u-turn instruction as the first instruction if the first heading is going into the opposite way of the requested heading. This should be actually quite easy as well. This could be done in the PathMerger or in a new class "InstructionMerger"? |
Yes it could be done in PathMerger or if necessary in a new class. |
Another idea could be to post-process the instructions after their generation. |
Ok, I updated the code. I create a u-turn instruction for waypoints, this means if we are going from I also added an initial u-turn if there was a heading for the first point and if the heading is pointing in the other direction than the heading of the first edge. (Diff > 170°) After giving this some more thought I am not sure if it is a good idea to calculate an initial u-turn on the server side. Think about a user is parked in his garage and plans a route. The heading might be completely off at this point. Once the route is calculated he wants to start the navigation and starts riding. The first instruction would be "turn around", which is a bit weird. Probably we should add some logic on the client side for this, as the client knows the initial heading of the continue instruction. WDYT? Should we add this or should I remove this again? |
Something I just came up with could solve case 1). But this would require extra computation power. We could add the starting and end heading of every instruction. Essentially this would require 2 azimut calculations per instruction. This would allow us to check the instruction list for short instructions with repeating turn signs, like it would appear for u-turns in case 1). E.g.
I think the question is if we would want this or not? This would probably further decrease the ch speed. |
We also need an icon for the front end here. |
Note that in your example, being parked and planning a route, the GPS could return |
Yes, I had the same thought, see my comment above:
So I think we should remove it again. Let me know what you think. |
Sorry, I'm a bit late with this ... would you mind updating the PR? probably just recreate the translation files.
The heading variable is already something where the client can and should pass this information - or is this already solved (?)
Isn't one of those calculations already done in the instruction creation code? |
# Conflicts: # reader-osm/src/test/java/com/graphhopper/GraphHopperIT.java
Ok, so I updated this PR.
Yes, this is how I implemented it :). However, I am not sure if it wouldn't simply work better to do this on the client side. Here we could also check if the user is moving or not and all that. We could also add this to GH though. We could add a I am really not sure what we should do here? WDYT @devemux86, would you see this on the client or server side, and why?
Yes, well we could add the heading for every instruction and not just for via instructions which would make this easier in the end. Probably the best would be to solve this case during the instruction creation and not in a post processing step. Will try if it's possible. |
Why would this be necessary? Why not just omit the heading if it is unknown? (and then no u-turn instruction is created)
What exactly do you want to see on the client side?
Sounds good! |
Indeed what's the actual use case or do we complicate things? |
Ok, maybe I was thinking too complicated then :). Let's leave it as it is currently.
The initial U-turn when being parked parallel to a street and needing to start in the other direction as currently facing. I was just thinking that it might be easier/better to do this on the client side. |
That could very easily fail by GPS accuracy.. 🙁 |
Ok, I updated this PR. It contains 3 features:
Let me know what you think. |
# Conflicts: # web/src/main/webapp/js/main.js
I updated this PR. Now I am quite happy with the results. When running measurement this PR was even a bit faster than the current master (well it shouldn't actually be faster, but the performance impact is not that huge). I updated the first comment to contain the relevant information. |
Should we differentiate left and right U-turns (and adapt the signs accordingly) like @devemux86 mentioned? |
We could, but I am not sure if the cost use factor makes sense. The benefit would be to be able to create u turns in a certain direction. But I am not sure how often u-turns would be done in the "wrong" direction. The downside of this would be that we need a spatial rule index to check if we are in a left hand traffic country. An alternative would be to differentiate between turn around and u-turn. U turns would have a direction and would be calculated in the instruction class. Turn around would be calculated for via points in the path merger. I think differentiating between u turns and turn around would be a nice addition. WDYT? |
Btw I think "turn around" and "u turn" is a synonym, so we might need a different name :). |
That would be a benefit for other cases in the library too. BTW is there the thought to allow setting the rule of the road externally by the apps, instead to calculate it inside the library, or it's better to have it always inside? |
Yes true :). I am still not 100% sure if this wouldn't be easier done on the client side? Also the benefit for roundabouts is not that huge IMHO. I think for roundabouts it would interesting to calculate the exiting angle (we got that already, maybe we need a bit more info) and create a turn instruction image on demand. For example if we know that we exit 80° to the left and the we go right around (might be possible to calculate from the edge geometry) we could generate a perfectly matching image. Might be easy to do with on demand SVG creation? Just a crazy thought :), but that would be really cool.
Isn't it enough to have it on the client side? I think besides the direction of roundabouts the changes for the routing are not that big and this could be easily done on the client side? |
Client can calculate or simply request users to set the rule of the road for their region. |
# Conflicts: # core/src/main/java/com/graphhopper/util/Instruction.java
I just pushed a change. We now have Icon wise we could now use directed u-turn icons for the specified u-turns. For the unknown we could also create a more generic turn around icone, for example like this. WDYT? |
That icon is for right-hand traffic roundabouts, not u-turns. |
Yes, this was just an example :). We could also just turn around the continue straight arrow, so that it points in the other direction. Another option would be a u-turn symbol without an arrow head, yes. |
# Conflicts: # web/src/main/webapp/js/main.js
I just updated this PR and resolved the merge conflict. This should be mergeable now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I think afterwards we should compare measurement with 3 points, currently there are just 2 and then the PathMerger is probably not activated.
Thanks for merging this :). I couldn't follow your comment, sorry. What do you mean by that? |
In the measurement class we use 2 point for querying so there won't be any u-turn calculation. If we use 3 points we could better see the performance impact of this change. |
Ah, ok, now I understand what you mean by that. There are still u-turns, but no "via-point u-turns". Sounds good, should I create a PR that creates multi point routes? |
Just mean to do the perf comparison in this case. Not sure if such a thing is necessary in the long run. |
This PR fixes #1064. This PR is adding U-Turn instructions.
We recognize 3 types of U-Turns:
http://localhost:8989/?point=48.005027%2C7.997961&point=48.005874%2C7.999538&heading=230
http://localhost:8989/?point=48.017509%2C8.008572&point=48.019012%2C8.008116&point=48.018319%2C8.010836&vehicle=bike
http://localhost:8989/?point=47.996983%2C7.841899&point=47.996987%2C7.842087
The third method performs pretty well for cars and fixes most of the u-turns. One issue is that we require two turn instructions. In some cases we don't create a turn instruction because there is no other possible turn, in this case we cannot convert the instruction to a u-turn, e.g., here.
I also required that the road to u-turn on is a one way. I have seen some cases where a u-turn was created that is not a real u-turn. Here are some examples in Baden-Württemberg. I found these examples using measurement, with foot and printed the location of every u-turn. So these examples are not very frequent, but they exist:
When only showing u-turns for one-way streets the samples above don't produce turn instructions. When thinking about this a bit more I think usually u-turns are only relevant for major roads that are usually one-ways separated from each other with designated u-turn lanes or u-turning at traffic lights. So this limitation makes sense for me.
TODO: