Low-Level Api not working

Greetings everyone!

I am relatively new to graph hopper, and I have been trying to run the Dijkstra using the low level api.

I wanted to run this api using a .osm.pbf file, so I chose the berlin-latest.osm.pbf file. I also set “car” as the profile.

I first create the graph hopper instance, and instead of creating the base graph in the low level api example, I get it from the hopper instance, but pretty much follow the same steps as shown in the low level api example

Now when I run the Dijkstra for 2 points in berlin, I always get infinity as the weight, and it is unable to find the route.

Here is the code I used for the low-level api:

GraphHopper hopper = new GraphHopper();

hopper.setGraphHopperLocation(graphLocation);
Profile profile = new Profile("car").setVehicle("car").setWeighting("fastest");
hopper.setProfiles(profile);
hopper.setOSMFile("graphhopper/berlin.osm.pbf");
hopper.importOrLoad();

Snap fromSnap = hopper.getLocationIndex().findClosest(52.5301592,13.388860, EdgeFilter.ALL_EDGES);
Snap toSnap = hopper.getLocationIndex().findClosest(52.530259,13.352512,  EdgeFilter.ALL_EDGES);
List<Snap> snapList = new ArrayList<>();
snapList.add(fromSnap);
snapList.add(toSnap);

QueryGraph queryGraph =QueryGraph.create(hopper.getBaseGraph(), snapList);

EncodingManager em = hopper.getEncodingManager();
BooleanEncodedValue accessEncoded = em.getBooleanEncodedValue(VehicleAccess.key("car"));
DecimalEncodedValue speedEncoded = em.getDecimalEncodedValue(VehicleSpeed.key("car"));
Weighting weighting = new FastestWeighting(accessEncoded, speedEncoded);

Path path = new Dijkstra(queryGraph, weighting, TraversalMode.NODE_BASED)
    .calcPath(fromSnap.getClosestNode(), toSnap.getClosestNode());

Please let me know what I may be doing wrong? Thank you for your help!

1 Like

Are you sure this does not work? It worked for me (using berlin-220101.osm.pbf from Geofabrik). The code also looks right. The calculated distance was 3316m.

2 Likes

Thank you for your reply!
So here is what my output says, when I just printed out the “path”.
found: false, weight: 1.7976931348623157E308, time: 0, distance: 0.0, edges: 0

I went a bit further into the code and it seems like the weight for the first edge is constantly coming as positive Infinity, and it is unable to really process further. Any thoughts where I might be going wrong?
Or perhaps am I missing something from my code?

Update: This was really strange… it did end up working for berlin-220101.osm.pbf. But NOT for the berlin-latest.osm.pbf. If anyone has any idea why, please let me know :slight_smile:

Also, when I ran bidirectional algorithms, it was able to find the way in both the datasets.

I can confirm the path is not found for berlin-latests.osm.pbf. This is strange, indeed. I’ll take a look.

Also, when I ran bidirectional algorithms, it was able to find the way in both the datasets.

Using berlin-latest.osm.pbf I cannot find a path for neither Dijkstra nor DijkstraBidirectionRef, or which one did you use? Did you make sure you deleted the graph folder after you changed the map file?

1 Like

The reason that you don’t find a path is that there is a new footway in between the from coordinate and the next road that was only added after 220101:

hopper.getLocationIndex().findClosest(52.5301592,13.388860, EdgeFilter.ALL_EDGES); will return the next possible snap that is closest to the given coordinate (the green marker). But since this is a footway and you are using a car profile this road is inaccessible and so the routing algorithm does not find a path. So you need to use an edge filter that skips the footway and snaps to Borsigstraße instead:

  DefaultSnapFilter snapFilter = new DefaultSnapFilter(weighting, em.getBooleanEncodedValue(Subnetwork.key("car")));
        Snap fromSnap = hopper.getLocationIndex().findClosest(52.5301592,13.388860, snapFilter);
        Snap toSnap = hopper.getLocationIndex().findClosest(52.530259,13.352512, snapFilter);

The DefaultSnapFilter will make sure to not snap to a road that is inaccessible for the given weighting and also ignore subnetworks, which can also lead to paths that aren’t found.

1 Like

Thank you so much for you reply! This is really helpful.

To ensure that I can avoid these mishaps on my end going forward, I tried looking for documentation for some of these implementations, so that I will be able to know about features such as these → the default snap filter. I was not able to quite find them within the documentation provided on the github. Would you happen to know where can I find the documentation them? Or would I have to simply look through the code base?

Yes, I think it is best to look at the code base.

1 Like

Got it, thank you so much!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.