Why GH cannot find route?

I am trying to find out routes for some origin-destinations. But in many cases, I am not finding routes. For example: GH cannot find routes for ori (38.97283744506505, -77.0672090064377), -dest 38.94379914038951, -77.06624094663978). But Google map can find route for it.

I have extracted osm file from BBBike (as .pbf). I have previously used another routing platform to get the routes. I used the same .pbf file to transform to .osm file there and that platform easily found the routes. But GH cannot. What could be the reason behind it? What I can do to make it work?


There is no need to convert the PBF. You can use it directly.

Also as you can see on GraphHopper Maps, a route can be found for your start and destination coordinates.

Ohh… I think it was the old version I was using.

I just downloaded the new version and it works. However, I have one question. I was looking for com.graphhopper.storage.GraphHopperStorage but cannot find it. Where is that class? I was trying to find the osm ids of the route and found this one (OSM Data in GraphHopper 3.0). But it also does not work because it cannot import GraphHopperStorage class.

Can you please give me any suggestion?

It was removed for GH 6.0: Remove GraphHopperStorage by easbar · Pull Request #2606 · graphhopper/graphhopper · GitHub
It was more or less replaced by BaseGraph.java.

So, is there any other way to find the osm ids of a route? Please suggest me how I can work it out.

The osm way IDs can be retrieved very easily, at least with the current master version: Add OSM way ID encoded value by easbar · Pull Request #2701 · graphhopper/graphhopper · GitHub
You just need to add osm_way_id to graph.encoded_values and run the GraphHopper import again. You can then request the OSM way IDs as path details.
OSM node IDs are a different story, because they aren’t stored by GraphHopper so you would have to adjust the Java code accordingly.

I enabled osm_way_id to encoded values by turning on in config (config-example). Is that the right way to do?

graph.encoded_values: osm_way_id

Can you please tell me how to request osm_id as path detail? I tried with this

static GraphHopper createGraphHopperInstance(String ghLoc) {
GraphHopper hopper = new GraphHopper();
// specify where to store graphhopper files

    hopper.setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(false));

    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));

    return hopper;

public static void routing(GraphHopper hopper) {
    GHRequest req = new GHRequest(38.97283745, -77.06720901,38.94379886, -77.06623885).  

    GHResponse rsp = hopper.route(req);
     // handle errors
            if (rsp.hasErrors())
                throw new RuntimeException(rsp.getErrors().toString());

            ResponsePath path = rsp.getBest();

            // points, distance in meters and time in millis of the full path
            double distance = path.getDistance();
            long timeInMs = path.getTime();
            Map<String, List<PathDetail>> details = path.getPathDetails();

but when I tried following line, I get error

“Map<String, List> details = path.getPathDetails();”

Exception in thread “main” java.lang.UnsupportedOperationException: remove
at java.base/java.util.Iterator.remove(Iterator.java:102)
at java.base/java.util.AbstractCollection.remove(AbstractCollection.java:283)
at com.graphhopper.util.details.PathDetailsBuilderFactory.createPathDetailsBuilders(PathDetailsBuilderFactory.java:85)
at com.graphhopper.util.details.PathDetailsFromEdges.calcDetails(PathDetailsFromEdges.java:65)
at com.graphhopper.util.PathMerger.doWork(PathMerger.java:139)
at com.graphhopper.routing.Router.concatenatePaths(Router.java:304)
at com.graphhopper.routing.Router.routeVia(Router.java:273)
at com.graphhopper.routing.Router.route(Router.java:120)
at com.graphhopper.GraphHopper.route(GraphHopper.java:1227)
at com.graphhopper.example.RoutingExample_copy.routing(RoutingExample_copy.java:65)
at com.graphhopper.example.RoutingExample_copy.main(RoutingExample_copy.java:29)

What is the right way to request osm_ids as path details?

You probably need to do setPathDetails(new ArrayList<>(Arrays.asList("max_speed", "osm_way_id"))).

Calling remove, i.e. modifying the list of requested path details (and hence the request object), in PathDetailsBuilderFactory, seems wrong to me, though. This was only introduced very recently, @karussell?

Oh, sure. Will fix.

1 Like

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