Skip to content

Problem with via-point (virtual node) when cutting an area via osmosis #1984

Closed

Description

@karussell

Problematic test case that gives different answer for route Q to P when requesting "Q, P, R" vs. "Q, P" only:

@Test
public void edge_splitting_bug() {
    GraphHopperOSM hopper = new GraphHopperOSM();
    hopper.setEncodingManager(EncodingManager.create("car"));
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setOSMFile("../core/files/lauf-200115.osm.pbf");
    hopper.setProfiles(new ProfileConfig("profile").setVehicle("car").setWeighting("fastest"));
    hopper.importOrLoad();
    GraphHopperStorage graph = hopper.getGraphHopperStorage();
    LocationIndex locationIndex = hopper.getLocationIndex();
    FlagEncoder encoder = hopper.getEncodingManager().fetchEdgeEncoders().get(0);
    final FastestWeighting weighting = new FastestWeighting(encoder);
    final BooleanEncodedValue accessEnc = weighting.getFlagEncoder().getAccessEnc();
    EdgeFilter edgeFilter = new EdgeFilter() {
        @Override
        public boolean accept(EdgeIteratorState edgeState) {
            return edgeState.get(accessEnc) && !Double.isInfinite(weighting.calcEdgeWeight(edgeState, false))
                    || edgeState.getReverse(accessEnc) && !Double.isInfinite(weighting.calcEdgeWeight(edgeState, true));
        }
    };
    GHPoint p = new GHPoint(49.529355099741494, 11.296203940756207);
    GHPoint q = new GHPoint(49.523147, 11.293001);
    GHPoint r = new GHPoint(49.53027363148555, 11.293370881574472);

    // works
    List<GHPoint> points = Arrays.asList(p, q/*, r*/);
    // does not work
//        List<GHPoint> points = Arrays.asList(p, q, r);

    List<QueryResult> queryResults = new ArrayList<>(points.size());
    for (GHPoint point : points) {
        queryResults.add(locationIndex.findClosest(point.lat, point.lon, edgeFilter));
    }
    QueryGraph queryGraph = QueryGraph.lookup(graph, queryResults);
    Dijkstra dijkstra = new Dijkstra(queryGraph, queryGraph.wrapWeighting(weighting), TraversalMode.NODE_BASED);
    Path path = dijkstra.calcPath(queryResults.get(0).getClosestNode(), queryResults.get(1).getClosestNode());
    System.out.println(path);
    assertEquals(168.369, path.getWeight(), 0.1);
    assertEquals(168369, path.getTime(), 100);
    assertEquals(1053.846, path.getDistance(), 0.1);
}

lauf-200115.osm.pbf.zip

Here is the situation on a map:

image

Maybe a problem due to the area cutting. When zooming into the edge near the destination it seems to be a loop:

image

Activity

  1. easbar commented on Apr 20, 2020

    @easbar
    Member

    This map shows another strange property: Querying the location index with some point far away like lat=0,lon=0 does not yield an error yields a valid Snap, while for maps that were not extracted with Osmosis we seem to get an invalid Snap.

    Maybe the problems go away when we extract the map like this: #2134 (comment)?

  2. easbar commented on Dec 19, 2020

    @easbar
    Member

    I think I ran into this or a similar issue again. In OSMReader we calculate the towerNodeDistance using the entire pointList:

    double towerNodeDistance = distCalc.calcDistance(pointList);

    But later we only use the inner (pillar) points to set the way geometry and we silently assume that the first/last points of pointList are equal to the coordinates of the base/adj nodes:

    if (pointList.size() > 2)
    iter.setWayGeometry(pointList.shallowCopy(1, pointList.size() - 1, false));

    However, with the extract I got from Osmosis this assumption was violated: The first point in the pointList did not match the base node's coordinates. Therefore in my case towerNodeDistance = distCalc.calculateDistance(pointList) = edge.getDistance() was different to distCalc.calculateDistance(edge.fetchWayGeometry(FetchMode.ALL)). This in turn lead to a situation where the sum of the distances of two virtual edges was (very) different to the 'distance' of the edge that was split by the virtual node.

    I'm not sure yet if this is a data issue (osmosis corrupts the file) or a bug on our side. But in any case maybe we should add a consistency check to make sure that pointList.get(0) == basePoint and pointList.get(pointList.size()-1) == adjPoint.

  3. easbar commented on Dec 19, 2020

    @easbar
    Member

    The other thing I find strange here is that we first calculate the towerNodeDistance using all points, then use the result to set the edge's distance field, but before we store the geometry we simplify it. Should we not rather simplify the geometry first and then calculate the edge distance? Otherwise we store a distance that was calculated based on some pillar nodes that we do not keep which seems inconsistent. --> opened #2222 for this.

    Fun fact: It's been like this for more than seven years now: cb342a2

  4. easbar commented on Dec 19, 2020

    @easbar
    Member

    Here I added a check that compares edge.getDistance() with distCalc.calcDistance(edge.fetchWayGeometry(FetchMode.ALL)): 37768ff.

    In GraphHopperTest this makes four tests fail. For example in testOneWaySubnetwork_issue1807 that uses the ESSEN map we get:

    Suspicious distance for edge: 5 1-25 43.129 vs. 32.10738463346008, difference: 11.021615366539919
    

    and in three SRTM tests that use monaco.osm.gz we get:

    Suspicious distance for edge: 5 1013-259 620.436 vs. 602.6416118459674, difference: 17.794388154032617
    
  5. easbar commented on Dec 19, 2020

    @easbar
    Member

    Regarding the initial issue in the first post here (edge_splitting_bug): The red marker (point R) introduces a virtual node along the loop edge seen in the close-up. This means when point R is included we get a different distance, because also here edge.getDistance() != calcDistance(edge.fetchWayGeometry(FetchMode.ALL)). With the distance check I introduced in my previous comment we also see this explicitly when we run the import for lauf-200115.osm.pbf:

    Suspicious distance for edge: 1007 1474-643 143.957 vs. 118.18903018395105, difference: 25.767969816048947
    
  6. easbar commented on Dec 21, 2020

    @easbar
    Member

    I'm not sure yet if this is a data issue (osmosis corrupts the file) or a bug on our side.

    I think I figured this out. The problem is that after extracting a bounding box using Osmosis there can be ways that reference nodes that no longer exist in the OSM file. And this leads to wrong edge distances. See #2221

  7. easbar commented on Dec 29, 2020

    @easbar
    Member

    Fixed via #2221

  8. added this to the 3.0 milestone on Dec 29, 2020
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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions