Skip to content

Requests with #Points > 2, duplicated points at waypoints #1139

Open

Description

@boldtrn

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.

{
distance: 0,
sign: 5,
interval: [
2,
3
],
text: "Waypoint 1",
time: 0,
street_name: ""
},
{
distance: 33.387,
sign: 0,
interval: [
3,
4
],
text: "Continue onto Waldhüttenstraße",
time: 7512,
street_name: "Waldhüttenstraße"
},

Activity

  1. karussell commented on Aug 18, 2017

    @karussell
    Member

    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 ...

  2. boldtrn commented on Aug 21, 2017

    @boldtrn
    MemberAuthor

    Let's discuss this here instead of in #1138 :).

    Hmmh, this feels wrong and we should probably skip adding the via points opposed to my recent comment in #1139?

    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?

  3. karussell commented on Aug 21, 2017

    @karussell
    Member

    What do you mean? Should we change the instructions then?

    Can we avoid adding points from a ViaInstruction to the "fullPoins" in PathMerger?

    Something like:

    if(!(i instanceof FinishInstruction) || pathIndex + 1 == paths.size())
       fullPoints.add(i.getPoints());
  4. karussell commented on Aug 21, 2017

    @karussell
    Member

    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]

  5. boldtrn commented on Aug 22, 2017

    @boldtrn
    MemberAuthor

    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:

    {
    distance: 0,
    sign: 5,
    interval: [
    2,
    3
    ],
    text: "Waypoint 1",
    time: 0,
    street_name: ""
    },
    {
    distance: 33.387,
    sign: 0,
    interval: [
    2,
    3
    ],
    text: "Continue onto Waldhüttenstraße",
    time: 7512,
    street_name: "Waldhüttenstraße"
    },
    

    Currently the normal instructions have the interval [from, last-1] and the ViaInstructions and FinishInstructions have [from,last]

    Are you sure? To me it looks like the other way around.

    In InstructionList#createJson we do:

    // the last instruction should not point to the next instruction
    if (counter + 1 == instructions.size())
       tmpIndex--;
    
  6. karussell commented on Aug 22, 2017

    @karussell
    Member

    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).

  7. boldtrn commented on Aug 22, 2017

    @boldtrn
    MemberAuthor

    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.

  8. karussell commented on Aug 22, 2017

    @karussell
    Member

    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.

  9. devemux86 commented on Aug 22, 2017

    @devemux86
    Contributor

    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]

    Indeed that's more logical.

  10. devemux86 commented on Aug 26, 2017

    @devemux86
    Contributor

    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.

  11. boldtrn commented on Aug 27, 2017

    @boldtrn
    MemberAuthor

    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.

    For example have a look at this routing request.

    It has only 2 points. The instructions look like this:

    instructions: [
    {
    distance: 3.928,
    sign: 0,
    interval: [
    0,
    1
    ],
    text: "Continue onto K 6720",
    time: 220,
    street_name: "K 6720"
    },
    {
    distance: 0,
    sign: 4,
    interval: [
    1,
    1
    ],
    text: "Arrive at destination",
    time: 0,
    street_name: ""
    }
    ]
    

    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

    All path details currently work this way: you specify first and last and the length is last-first.

    I finally understood the issue.

    Think about this turn:

    A ----- B
             |
             C
    

    If you route from A->C. The PathDetails for the street name would be:

    details: {
    street_name: [
    [
    0,
    1,
    "A-B"
    ],
    [
    1,
    2,
    "B-C"
    ]
    ]
    }
    

    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:

    instructions: [
    {
    distance: 9.613,
    sign: 0,
    interval: [
    0,
    1
    ],
    text: "Continue onto A-B",
    time: 692
    },
    {
    distance: 7,
    sign: 2,
    interval: [
    1,
    2
    ],
    text: "Turn right onto B-C",
    time: 280
    },
    {
    distance: 0,
    sign: 4,
    interval: [
    2,
    2
    ],
    text: "Arrive at destination",
    time: 0,
    street_name: ""
    }
    ]
    

    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?

  12. devemux86 commented on Aug 27, 2017

    @devemux86
    Contributor

    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.

  13. devemux86 commented on Aug 27, 2017

    @devemux86
    Contributor

    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.

  14. karussell commented on Aug 27, 2017

    @karussell
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions