You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add speed, time and more informations to instructions #439
It'd be useful to get the speed of route segments returned in a GHResponse. Not clear to me how to expose it though (add it to points or an array of speeds or something else?)
Yes, would be nice and it should be already relative easy to customize GraphHopper to do so. But for GraphHopper itself we need a more generic functionality that could also return road type, surface, CO2 usage and more. So this issue is also related to #311
Also the question is if one should return the used speed or the maximum allowed speed of that segment and how granular one describes this information e.g. per junction or even per coordinate or just per instruction.
I came across something that would suit a more generic functionality the other day. I noticed that a park that I could use for walks between the 32nd Chaos Communication Congress and my hotel was closed at night. After tweeting about it and including a link to a Graphhopper routing (only for illustration), I was eventually pointed to this issue. See https://twitter.com/SebaLis/status/681440331754270720 – although I had never expected Graphhopper to do anything different from what it had done. (As I wrote in the thread, I only meant to lightly complain about the park being something of a "gated community", which also happened to be the congress motto.) It was only after SK53 and karussell responded that I started thinking about ways to handle this in Graphhopper.
So, imagine there is a routing that uses segments with any kind of restriction – an area or gate that is closed at certain times, a road with tolls or non-default speed limits, an underpass with a maximum height, a bridge with maximum weight etc. I think it would be good to first return the original (optimal, unrestricted) solution together with a hint that it has certain restrictions. This could be displayed in the style of a warning icon with a minimal amount of text pointing to the fact that there are restrictions, perhaps mentioning the type(s) but nothing more. The user could then click on the warning to reveal all the details and a set of form elements relevant to the restriction(s). So this would be an input for the time when the user wants to use the routing, checkboxes to avoid toll roads or speed restrictions, inputs for height or weight of the user’s vehicle. After completing and submitting this extra form, the route could be recalculated with those extra conditions taken into account.
Thanks for your work, I hope my idea will be useful in some way. :-)
I've thought about this a bit more and instead of attaching this to the instructions we should create a new details sections. This way we can show all the details not just a summary of the streets between turns. Also interesting to fetch arbitrary OSM data from a route and potentially interesting for the map matching component.
The only problem is the potential big result set for long routes, but we could optimize this a bit via using the interval instead of repeating the geometry here again. Here is what I thought:
The interval notation is used identical to the instructions pointing with the index into the points array. To save a bit space one could also use [index, offset] instead, not sure. We need to find a balance between simplicity and compactness.
Furthermore all these key|value pairs should be more or less independent from OSM as we have to support other data sets here.
Additionally we could provide a statistics entry doing some simple average or max/min calculations for every key|value pair:
Lastly we can even point out the internal edge representation for debugging purposes as well as for an efficient way on the client side to split the data into meaningful 'street segments':
@karussell I am just getting started with graphhopper but like to add surface information as a proof of concept into the api response. I also think that having a seperate section like you proposed would make sense. Before I continue digging into the code to see where I might get started... did you already start on something? Can you point me to the places in code I should have a look at to get going?
Alright... I started having some kind of success...
So Path.java I suppose is the route that is described?!? I started playing around there... I thought that the function private void forEveryEdge(EdgeVisitor visitor) would get called for every edge of the final path but that's not correct right? Cause on my sample final path with 5 points, this is called 10 times (this is because of the simplify at the end?!?). Also when I have a DataFlagEncoder in there and output the surface to the console like so: getSurfaceAsString(edgeBase) it outputs a surface that it's not...
In my sample request point=52.51088,13.34554&point=52.509577,13.348855 it's only grass... even if it should be asphalt or something like this... ?!?
So can I just create an instance of DataFlagEncoder and through the edge at it?
Alright... I think I don't understand the underlying system well enough... So the encoders are encoding only the information they need upfront? So basically in my test the bike2 encoder just doesn't store surface information, right? It does store the way-type but not surface info? Am I correct?
What is the current state of this issue? There seems to be no way to obtain surface information of routes, right?
No, we currently don't pass that information, but we could also do this in this issue.
Before I continue digging into the code to see where I might get started... did you already start on something? Can you point me to the places in code I should have a look at to get going?
I actually don't think that there has been an actual implementation approach here (but I might be wrong).
Alright... I started having some kind of success...
So your approach sounds good to me, I would have done more or less the same. Go to the Path class and do it for every edge, using the DataFlagEncoder.
getSurfaceAsString(edgeBase) it outputs a surface that it's not...
In my sample request point=52.51088,13.34554&point=52.509577,13.348855 it's only grass... even if it should be asphalt or something like this... ?!?
That sounds weird, maybe there is a bug in your code. I just checked the DataFlagEncoder, the behavior looks correct, I wrote a short test here (which succeeded):
Alright... I think I don't understand the underlying system well enough... So the encoders are encoding only the information they need upfront? So basically in my test the bike2 encoder just doesn't store surface information, right? It does store the way-type but not surface info? Am I correct?
Generally speaking, yes, even though I am not sure if bike2 stores the way-type? (I actually think it does not?)
I think you had a good start, is your code on Github? I might have a brief look.
@boldtrn you can have a look at what I did here: georgbachmann@109c703
It's already working and outputting it through the API... Not sure if I am happy with the response.. I guess I'll tweak that... But for what I need it's currently working already... Also naming is terrible right now :) have to think of more appropriate variable names ;)
Also what I was missing before, I have to use graph.flag_encoders=generic to get it working (didn't know that)
But maybe you have a tip for me there... when I use this generic flag, I can only use hike and mtb along with it, anything more will make it say that it hasn't enough bits..?!?
@georgbachmann nice, looks good. Would you be interested in creating this in a more generic form as a PR for GraphHopper? Maybe with the response formatted as proposed by @karussellhere.
But maybe you have a tip for me there... when I use this generic flag, I can only use hike and mtb along with it, anything more will make it say that it hasn't enough bits..?!?
Ah your usage of the DataFlagEncoder sounds interesting. So you are just using it as a DataStorage along other Encoders. You can use graph.bytes_for_flags=8 in your config. This is currently the limit for GraphHopper. Related to #978 and #1036. As a quickfix for your project, you could move the highway/surface information to one of your encoders (mtb, hike, ...) or remove stored information from the DataFlagEncoder, like speed, access, etc.
I improved my API-Response a bit to better match what @karussell was proposing... Hope I will have more time soon to do some more cleanup.
About my use of DataFlagEncoder... i just wasn't sure how to use it properly (don't have that much time to spend on that topic unfortunately) , but that way it was working :) So basically I would have to check if the encoder used has surface-information and then add them if they are available?!? And then if somebody would add surface-information to f.e. a hike profile, they will have this information in the response?!? But the information about surfaces is only inside the DataFlagEncoder, isn't it?
I guess I'd need some more understanding here to properly provide a more generic solution than the one I have right now...
So basically I would have to check if the encoder used has surface-information and then add them if they are available?!?
I am not entirely sure how we should approach this. It should be independent from the surface information. I think the best would be that a user requests surface details for a route, then we would add surface information, if available. The same applies for other details, like speed, highway type, etc. So the user could decide that (s)he is interested in speed and surface, then we would add these details. So this would probably be a DataFlagEncoder feature (at least in the first step). WDYT @karussell?
The only problem is the potential big result set for long routes, but we could optimize this a bit via using the interval instead of repeating the geometry here again.
I just started to work on this issue by adding average speed. When thinking about the interval a bit more, there is an issue with the simplification algorithm.
If we show instructions, we simplify the geometry between the instructions, which works well. But when adding intervals on an edge base (the smallest interval for this issue is one edge), this would mean that we can only simplify the points of every edge, because we need the first and last point of every edge to exist in the geometry, so we can reference it.
A different option would be store coordinates instead of intervals, so we could store the start coordinate and the end coordinate.
We could also try to find the closest point in the point list. This would take more time to calculate, but certainly possible.
And yes, simplification makes this more complex ;)
A simple start would be to fall back to way_point_max_distance=0 when such a details option is used, i.e. disable simplification. If details just contains 'average speed' we could still simplify over several edges for which the speed does not change. But in certain cases like when we return traversal keys ('edge Ids') then disabling simplification is still necessary.
A different option would be store coordinates instead of intervals, so we could store the start coordinate and the end coordinate.
This is already done indirectly (?) as the interval refers to the points array not to the edge index.
If details just contains 'average speed' we could still simplify over several edges for which the speed does not change.
Yes, if they belong to one instruction :). So it becomes a bit complicated.
This is already done indirectly (?) as the interval refers to the points array not to the edge index.
Yes, but if we simplify it, we cannot reference it, so we can simply add the coordinates, for each segment. The result might be smaller and we could encode the coordinates here. Creating only coordinates without matching them to the points is also easier to implement (I think). In the end the result might be smaller compared not simplified option.
Something we could also consider is to add a second geometry, containing the coordinates of every tower node on the route (not simplified). This should be enough to reference the points.
What do you mean with this? What is the difference between coordinates & points?
Sorry hard to explain without writing a sample, but I am currently using my mobile. I meant to put in the actual coordinates in the details section instead of referencing the points array. If the matching point is not in the points array because it was simplified, then this would not be a problem (I think).
I meant to put in the actual coordinates in the details section instead of referencing the points array
Not sure I understand correctly but coordinates themselves like [lon,lat] are a huge waste of space in the JSON, especially as we plan to return details for multiple properties.
Not sure I understand correctly but coordinates themselves like [lon,lat] are a huge waste of space in the JSON, especially as we plan to return details for multiple properties.
Yes, that's why I thought about this:
Something we could also consider is to add a second geometry, containing the coordinates of every tower node on the route (not simplified). This should be enough to reference the points.
We can furth optimize this by only adding the coordinates that are needed for the given detail section. I am not sure if this is better than not simplifying?
Example:
"details": {
"points": [ [ lon1, lat1], [ lon2, lat2], ... ] <- could be encoded
"average-speed": {
"50" : [[1,2],..] <- This references the points above and not the global points array
}
}
We can further optimize this by only adding the coordinates that are needed for the given detail section.
We should just use one global points array and avoid duplication. So treat average-speed like instructions and create a list of points that cannot be simplified and in-between we still use simplify. This needs a bit more refactoring as it is a bit ugly that the instructions are created in SimpleRouteSerializer and not e.g. when the GHResponse is created, but hopefully will lead to a cleaner system and the JSON (and GPX) output will use the created instructions and the details objects instead of wrangling with the details on their own.
If I read issue #1091 correctly then it is only about adding speed information. This issue (and my interest in it) is also about other restrictions such as times when a segment is closed, tolls, height or weight restrictions etc. If these have not been addressed in the other issue then I believe this issue should remain open.
Github fixed this here automatically :) ... but indeed #1091 'only' builds a foundation that makes the other stuff much easier to implement. Another necessary step for this here is #1112 that will come in the next weeks hopefully.
Activity
karussell commentedon Jun 9, 2015
Yes, would be nice and it should be already relative easy to customize GraphHopper to do so. But for GraphHopper itself we need a more generic functionality that could also return road type, surface, CO2 usage and more. So this issue is also related to #311
Also the question is if one should return the used speed or the maximum allowed speed of that segment and how granular one describes this information e.g. per junction or even per coordinate or just per instruction.
sebalis commentedon Jan 2, 2016
I came across something that would suit a more generic functionality the other day. I noticed that a park that I could use for walks between the 32nd Chaos Communication Congress and my hotel was closed at night. After tweeting about it and including a link to a Graphhopper routing (only for illustration), I was eventually pointed to this issue. See https://twitter.com/SebaLis/status/681440331754270720 – although I had never expected Graphhopper to do anything different from what it had done. (As I wrote in the thread, I only meant to lightly complain about the park being something of a "gated community", which also happened to be the congress motto.) It was only after SK53 and karussell responded that I started thinking about ways to handle this in Graphhopper.
So, imagine there is a routing that uses segments with any kind of restriction – an area or gate that is closed at certain times, a road with tolls or non-default speed limits, an underpass with a maximum height, a bridge with maximum weight etc. I think it would be good to first return the original (optimal, unrestricted) solution together with a hint that it has certain restrictions. This could be displayed in the style of a warning icon with a minimal amount of text pointing to the fact that there are restrictions, perhaps mentioning the type(s) but nothing more. The user could then click on the warning to reveal all the details and a set of form elements relevant to the restriction(s). So this would be an input for the time when the user wants to use the routing, checkboxes to avoid toll roads or speed restrictions, inputs for height or weight of the user’s vehicle. After completing and submitting this extra form, the route could be recalculated with those extra conditions taken into account.
Thanks for your work, I hope my idea will be useful in some way. :-)
[-]Add speed to instructions[/-][+]Add speed and more informations to instructions[/+]karussell commentedon Apr 4, 2016
I've thought about this a bit more and instead of attaching this to the instructions we should create a new
detailssections. This way we can show all the details not just a summary of the streets between turns. Also interesting to fetch arbitrary OSM data from a route and potentially interesting for the map matching component.The only problem is the potential big result set for long routes, but we could optimize this a bit via using the interval instead of repeating the geometry here again. Here is what I thought:
The interval notation is used identical to the instructions pointing with the index into the
pointsarray. To save a bit space one could also use[index, offset]instead, not sure. We need to find a balance between simplicity and compactness.Furthermore all these key|value pairs should be more or less independent from OSM as we have to support other data sets here.
Additionally we could provide a
statisticsentry doing some simple average or max/min calculations for every key|value pair:Lastly we can even point out the internal edge representation for debugging purposes as well as for an efficient way on the client side to split the data into meaningful 'street segments':
Where
lengthsis the number of coordinates for each edge and an edge is then the connection between two junctions.devemux86 commentedon Apr 4, 2016
Are these descriptions regarding the web api?
Will they be connected to the code, e.g. retrieving the road type for an edge?
karussell commentedon Apr 4, 2016
Of course this means also having a Java API for this. But e.g.
surface:unpavedis already possible for bike andavg-speedfor all ;)[-]Add speed and more informations to instructions[/-][+]Add speed, time and more informations to instructions[/+]rmnblm commentedon Apr 4, 2017
What is the current state of this issue? There seems to be no way to obtain surface information of routes, right?
georgbachmann commentedon Apr 13, 2017
@karussell I am just getting started with graphhopper but like to add surface information as a proof of concept into the api response. I also think that having a seperate section like you proposed would make sense. Before I continue digging into the code to see where I might get started... did you already start on something? Can you point me to the places in code I should have a look at to get going?
Alright... I started having some kind of success...
So
Path.javaI suppose is the route that is described?!? I started playing around there... I thought that the functionprivate void forEveryEdge(EdgeVisitor visitor)would get called for every edge of the final path but that's not correct right? Cause on my sample final path with 5 points, this is called 10 times (this is because of the simplify at the end?!?). Also when I have aDataFlagEncoderin there and output the surface to the console like so:getSurfaceAsString(edgeBase)it outputs a surface that it's not...In my sample request
point=52.51088,13.34554&point=52.509577,13.348855it's only grass... even if it should be asphalt or something like this... ?!?So can I just create an instance of
DataFlagEncoderand through the edge at it?Alright... I think I don't understand the underlying system well enough... So the encoders are encoding only the information they need upfront? So basically in my test the
bike2encoder just doesn't store surface information, right? It does store the way-type but not surface info? Am I correct?boldtrn commentedon Apr 19, 2017
No, we currently don't pass that information, but we could also do this in this issue.
I actually don't think that there has been an actual implementation approach here (but I might be wrong).
So your approach sounds good to me, I would have done more or less the same. Go to the Path class and do it for every edge, using the DataFlagEncoder.
That sounds weird, maybe there is a bug in your code. I just checked the DataFlagEncoder, the behavior looks correct, I wrote a short test here (which succeeded):
Generally speaking, yes, even though I am not sure if bike2 stores the way-type? (I actually think it does not?)
I think you had a good start, is your code on Github? I might have a brief look.
georgbachmann commentedon Apr 19, 2017
@boldtrn you can have a look at what I did here: georgbachmann@109c703
It's already working and outputting it through the API... Not sure if I am happy with the response.. I guess I'll tweak that... But for what I need it's currently working already... Also naming is terrible right now :) have to think of more appropriate variable names ;)
Also what I was missing before, I have to use
graph.flag_encoders=genericto get it working (didn't know that)But maybe you have a tip for me there... when I use this generic flag, I can only use hike and mtb along with it, anything more will make it say that it hasn't enough bits..?!?
boldtrn commentedon Apr 22, 2017
@georgbachmann nice, looks good. Would you be interested in creating this in a more generic form as a PR for GraphHopper? Maybe with the response formatted as proposed by @karussell here.
Ah your usage of the DataFlagEncoder sounds interesting. So you are just using it as a DataStorage along other Encoders. You can use
graph.bytes_for_flags=8in your config. This is currently the limit for GraphHopper. Related to #978 and #1036. As a quickfix for your project, you could move the highway/surface information to one of your encoders (mtb, hike, ...) or remove stored information from the DataFlagEncoder, like speed, access, etc.georgbachmann commentedon Apr 24, 2017
I improved my API-Response a bit to better match what @karussell was proposing... Hope I will have more time soon to do some more cleanup.
About my use of
DataFlagEncoder... i just wasn't sure how to use it properly (don't have that much time to spend on that topic unfortunately) , but that way it was working :) So basically I would have to check if the encoder used has surface-information and then add them if they are available?!? And then if somebody would add surface-information to f.e. a hike profile, they will have this information in the response?!? But the information about surfaces is only inside the DataFlagEncoder, isn't it?I guess I'd need some more understanding here to properly provide a more generic solution than the one I have right now...
boldtrn commentedon Apr 25, 2017
Happy to hear that!
@georgbachmann we are planning to work on this as well, see this project.
I am not entirely sure how we should approach this. It should be independent from the surface information. I think the best would be that a user requests surface details for a route, then we would add surface information, if available. The same applies for other details, like speed, highway type, etc. So the user could decide that (s)he is interested in speed and surface, then we would add these details. So this would probably be a DataFlagEncoder feature (at least in the first step). WDYT @karussell?
boldtrn commentedon Jun 12, 2017
I just started to work on this issue by adding average speed. When thinking about the interval a bit more, there is an issue with the simplification algorithm.
If we show instructions, we simplify the geometry between the instructions, which works well. But when adding intervals on an edge base (the smallest interval for this issue is one edge), this would mean that we can only simplify the points of every edge, because we need the first and last point of every edge to exist in the geometry, so we can reference it.
A different option would be store coordinates instead of intervals, so we could store the start coordinate and the end coordinate.
We could also try to find the closest point in the point list. This would take more time to calculate, but certainly possible.
WDYT?
karussell commentedon Jun 13, 2017
Great :) !
And yes, simplification makes this more complex ;)
A simple start would be to fall back to
way_point_max_distance=0when such adetailsoption is used, i.e. disable simplification. If details just contains 'average speed' we could still simplify over several edges for which the speed does not change. But in certain cases like when we return traversal keys ('edge Ids') then disabling simplification is still necessary.This is already done indirectly (?) as the
intervalrefers to thepointsarray not to the edge index.boldtrn commentedon Jun 13, 2017
Yes, if they belong to one instruction :). So it becomes a bit complicated.
Yes, but if we simplify it, we cannot reference it, so we can simply add the coordinates, for each segment. The result might be smaller and we could encode the coordinates here. Creating only coordinates without matching them to the points is also easier to implement (I think). In the end the result might be smaller compared not simplified option.
Something we could also consider is to add a second geometry, containing the coordinates of every tower node on the route (not simplified). This should be enough to reference the points.
WDYT?
karussell commentedon Jun 13, 2017
What do you mean with this? What is the difference between coordinates & points?
boldtrn commentedon Jun 13, 2017
Sorry hard to explain without writing a sample, but I am currently using my mobile. I meant to put in the actual coordinates in the details section instead of referencing the points array. If the matching point is not in the points array because it was simplified, then this would not be a problem (I think).
karussell commentedon Jun 13, 2017
Not sure I understand correctly but coordinates themselves like
[lon,lat]are a huge waste of space in the JSON, especially as we plan to return details for multiple properties.boldtrn commentedon Jun 14, 2017
Yes, that's why I thought about this:
We can furth optimize this by only adding the coordinates that are needed for the given detail section. I am not sure if this is better than not simplifying?
Example:
karussell commentedon Jun 14, 2017
We should just use one global points array and avoid duplication. So treat average-speed like instructions and create a list of points that cannot be simplified and in-between we still use simplify. This needs a bit more refactoring as it is a bit ugly that the instructions are created in SimpleRouteSerializer and not e.g. when the GHResponse is created, but hopefully will lead to a cleaner system and the JSON (and GPX) output will use the created instructions and the details objects instead of wrangling with the details on their own.
sebalis commentedon Aug 16, 2017
If I read issue #1091 correctly then it is only about adding speed information. This issue (and my interest in it) is also about other restrictions such as times when a segment is closed, tolls, height or weight restrictions etc. If these have not been addressed in the other issue then I believe this issue should remain open.
karussell commentedon Aug 16, 2017
Github fixed this here automatically :) ... but indeed #1091 'only' builds a foundation that makes the other stuff much easier to implement. Another necessary step for this here is #1112 that will come in the next weeks hopefully.
karussell commentedon Sep 10, 2018
Closing in favour of #1140