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
Requests with #Points > 2, duplicated points at waypoints #1139
I just understood the issue with the extra point for requests which have via points, that we discussed here.
When there is a GHRequest with for example 3 Points. We merge two Paths. Usually, the last point of the first Path is equal to the first point of the second Path. Right now we just append the two Paths. This leads to a duplication of points. For example have a look at this route.
The resulting points json looks like this:
points: {
coordinates: [
[
11.498807,
49.984347
],
[
11.499067,
49.98446
],
[
11.499214,
49.984541
],
=============================
Here is the waypoint, you see that the point above and below are duplicated
=============================
[
11.499214,
49.984541
],
[
11.499627,
49.984682
]
],
type: "LineString"
},
Overall, this is not very critical. The better or cleaner solution would probably be to not duplicate these points, but we would have to change our instructions then.
Right now the ViaPointInstruction, references the first duplicated point. The ContinueInstruction references the second duplicated point. If we remove one of these points, we could not continue with this pattern.
but we would have to change our instructions then.
Yes, I would postpone this when we make instructions a new PathDetail? Otherwise this feels a bit artificial if we skip all via points that have just one point but the FinishInstruction will be added as all instructions do not include the last point ...
What do you mean? Should we change the instructions then?
We could remove the first point of the first instruction, for every Path, except the first Path. But what happens if the first instruction after the via-point has only one point?
Or should we make the correct but Java-API-breaking refactoring? Currently the normal instructions have the interval [from, last-1] and the ViaInstructions and FinishInstructions have [from,last]. The interval [from,last] should be the default but then we should ignore all instructions with last-from<1. This would then also be in sync with the PathDetails that also have [first,last]
Can we avoid adding points from a ViaInstruction to the "fullPoins" in PathMerger?
Or should we make the correct but Java-API-breaking refactoring?
I think that, your described change would not fix the issue. The issue is that the ViaInstruction and the next instruction after the ViaInstruction reference the same coordinate.
Currently, every point in the points array, belongs to exactly one Instruction. So the "correct" change would be to break this assumption. To use the example given above, we would remove the duplicated point
[
11.499214,
49.984541
]
Then we would have to change the references of the Instructions to:
I think (95% sure ;)) the current state for two paths (size 10 and 10) with a via point is 20 points:
[0, 8], [9, 9], [10, 19]
I.e. the first path is artificially splitted into 0,8 and the via point at index 9.
But instead it should be:
[0, 9], [9, 9], [9, 18]
where the point at index 10 is the end point of the first and the via point and the start point of the second path but it should not be duplicated in the final PointList as it is now. And the total length would be only 19 points (10+10-1 due to one overlapping point). This way the instructions would be in-line with the PathDetails.
Maybe one misunderstanding comes from the fact that the current notation [9,9] for the via point is not consistent (length==1) with the PathDetail which would be length of 0 (due to 9-9).
For example look at this request. You can see that the 9,9 example is true for the finish instruction, but not the via instruction. For the via instruction it would be 8,9.
You can see that the 9,9 example is true for the finish instruction, but not the via instruction. For the via instruction it would be 8,9.
Yes, it is inconsistent. But isn't it [9,10]?
So, I think the current state is: [0, 9], via:[9, 10], [10, 19], finish:[19, 19]
Which does not make much sense as a via point should be just one point.
And it should be: [0, 9], via:[9, 9], [9, 18], finish:[18, 18]
A further problem is also on the Java side: here we measure a length of a ViaInstruction with the help of PointList.size which would be 1 instead of last-first which would be 0.
I think seeing different behavior between clients: Java vs Web.
Java client returns open [x,y) instruction intervals, while Web client returns closed [x,y] ones?
e.g. for a small path with 2 instructions and pointList.size() = 2, iterating instruction.getPoints().size() returns 1+1 points in Java and 2+1 points in Web.
Java client returns open [x,y) instruction intervals, while Web client returns closed [x,y] ones?
With Java client you mean that you include GraphHopper as a lib and call the calcPaths method locally? With web you mean the json interface or do you mean the java client?
The Java interface does not really provide you any intervals, only point sizes.
The continue instruction has 1 point. The finish instruction has 1 point. The second number of the interval points to the next instruction. Example [0,1], here the next instruction would start at the point with the index 1.
This is the current state of the API.
When thinking more about this, this actually seems wrong. I think the second number of the interval should point to the last point of the instruction.
From point 0 (A) to point 1 (B). We are on the street A-B. From point 1 (B) to point 2 (C) we are on the street "B-C". So the path details are correct.
For the same situation the instructions right now, would look like:
Which is also correct. The problem of the instructions are the format of the instructions, as instructions contain points and no index references. When we calculate the points of a route, we don't duplicate the points at the end/beginning of an edge. Therefore we have to use "hacks" in the serialization to artificially set points of some to size 0.
I think we should change the format of the instructions to become more similar to the PathDetails, by not containing points, but only from and to references.
In both cases I mean the Java clients, GraphHopper from graphhopper-core using offline graph and GraphHopperWeb from directions-api-client-hc using an online server (tested GraphHopper and Kurviger the same).
Sorry when mentioned "intervals" above, it was the Java instruction point sizes. 🙂
Iterating instruction.getPoints().size() returns inconsistent results between the two clients for the exact same route.
The directions-api-client-hc client has +1 point sizes in the response instructions than the graphhoppcer-core.
With directions-api-client-hc client, each instruction (except the final) has in its PointList as last point also the 1st point of the next instruction.
This is not happening with graphhopper-core client, where the instructions PointList end at previous point from the next instruction.
Iterating instruction.getPoints().size() returns inconsistent results between the two clients for the exact same route.
Yeah, this could be. But I think the current Java API for gh-core is wrong and not the hc client.
I think we should change the format of the instructions to become more similar to the PathDetails, by not containing points, but only from and to references.
Yes, this would be perfect (including the problem with the PointList that @devemux86 found) but we can also do this as a later step if too much effort. As a first step we can fix the interval 'bug' of the ViaInstructions.
Activity
karussell commentedon Aug 18, 2017
Yes, I would postpone this when we make instructions a new PathDetail? Otherwise this feels a bit artificial if we skip all via points that have just one point but the FinishInstruction will be added as all instructions do not include the last point ...
boldtrn commentedon Aug 21, 2017
Let's discuss this here instead of in #1138 :).
What do you mean? Should we change the instructions then?
We could remove the first point of the first instruction, for every Path, except the first Path. But what happens if the first instruction after the via-point has only one point?
karussell commentedon Aug 21, 2017
Can we avoid adding points from a ViaInstruction to the "fullPoins" in PathMerger?
Something like:
karussell commentedon Aug 21, 2017
Or should we make the correct but Java-API-breaking refactoring? Currently the normal instructions have the interval
[from, last-1]and the ViaInstructions and FinishInstructions have[from,last]. The interval[from,last]should be the default but then we should ignore all instructions with last-from<1. This would then also be in sync with the PathDetails that also have[first,last]boldtrn commentedon Aug 22, 2017
I think that, your described change would not fix the issue. The issue is that the ViaInstruction and the next instruction after the ViaInstruction reference the same coordinate.
Currently, every point in the points array, belongs to exactly one Instruction. So the "correct" change would be to break this assumption. To use the example given above, we would remove the duplicated point
Then we would have to change the references of the Instructions to:
Are you sure? To me it looks like the other way around.
In InstructionList#createJson we do:
karussell commentedon Aug 22, 2017
I think (95% sure ;)) the current state for two paths (size 10 and 10) with a via point is 20 points:
[0, 8], [9, 9], [10, 19]
I.e. the first path is artificially splitted into 0,8 and the via point at index 9.
But instead it should be:
[0, 9], [9, 9], [9, 18]
where the point at index 10 is the end point of the first and the via point and the start point of the second path but it should not be duplicated in the final PointList as it is now. And the total length would be only 19 points (10+10-1 due to one overlapping point). This way the instructions would be in-line with the PathDetails.
Maybe one misunderstanding comes from the fact that the current notation [9,9] for the via point is not consistent (length==1) with the PathDetail which would be length of 0 (due to 9-9).
boldtrn commentedon Aug 22, 2017
For example look at this request. You can see that the 9,9 example is true for the finish instruction, but not the via instruction. For the via instruction it would be 8,9.
karussell commentedon Aug 22, 2017
Yes, it is inconsistent. But isn't it [9,10]?
So, I think the current state is: [0, 9], via:[9, 10], [10, 19], finish:[19, 19]
Which does not make much sense as a via point should be just one point.
And it should be: [0, 9], via:[9, 9], [9, 18], finish:[18, 18]
A further problem is also on the Java side: here we measure a length of a ViaInstruction with the help of PointList.size which would be 1 instead of
last-firstwhich would be 0.devemux86 commentedon Aug 22, 2017
Indeed that's more logical.
devemux86 commentedon Aug 26, 2017
I think seeing different behavior between clients: Java vs Web.
Java client returns open [x,y) instruction intervals, while Web client returns closed [x,y] ones?
e.g. for a small path with 2 instructions and
pointList.size() = 2, iteratinginstruction.getPoints().size()returns 1+1 points in Java and 2+1 points in Web.boldtrn commentedon Aug 27, 2017
With Java client you mean that you include GraphHopper as a lib and call the calcPaths method locally? With web you mean the json interface or do you mean the java client?
The Java interface does not really provide you any intervals, only point sizes.
For example have a look at this routing request.
It has only 2 points. The instructions look like this:
The continue instruction has 1 point. The finish instruction has 1 point. The second number of the interval points to the next instruction. Example [0,1], here the next instruction would start at the point with the index 1.
This is the current state of the API.
When thinking more about this, this actually seems wrong. I think the second number of the interval should point to the last point of the instruction.
This was also pointed out by @karussell here
I finally understood the issue.
Think about this turn:
If you route from A->C. The PathDetails for the street name would be:
From point 0 (A) to point 1 (B). We are on the street A-B. From point 1 (B) to point 2 (C) we are on the street "B-C". So the path details are correct.
For the same situation the instructions right now, would look like:
Which is also correct. The problem of the instructions are the format of the instructions, as instructions contain points and no index references. When we calculate the points of a route, we don't duplicate the points at the end/beginning of an edge. Therefore we have to use "hacks" in the serialization to artificially set points of some to size 0.
I think we should change the format of the instructions to become more similar to the PathDetails, by not containing points, but only from and to references.
WDYT?
devemux86 commentedon Aug 27, 2017
In both cases I mean the Java clients, GraphHopper from
graphhopper-coreusing offline graph and GraphHopperWeb fromdirections-api-client-hcusing an online server (tested GraphHopper and Kurviger the same).Sorry when mentioned "intervals" above, it was the Java instruction point sizes. 🙂
Iterating
instruction.getPoints().size()returns inconsistent results between the two clients for the exact same route.The
directions-api-client-hcclient has +1 point sizes in the response instructions than thegraphhoppcer-core.devemux86 commentedon Aug 27, 2017
With
directions-api-client-hcclient, each instruction (except the final) has in itsPointListas last point also the 1st point of the next instruction.This is not happening with
graphhopper-coreclient, where the instructionsPointListend at previous point from the next instruction.karussell commentedon Aug 27, 2017
Yeah, this could be. But I think the current Java API for gh-core is wrong and not the hc client.
Yes, this would be perfect (including the problem with the PointList that @devemux86 found) but we can also do this as a later step if too much effort. As a first step we can fix the interval 'bug' of the ViaInstructions.