Small error in Routing via Java API, setOSMFile being called on superclass without this method

There might be a small error in the ‘java usage’ section of the map-matching and the Routing via Java API page. In both instances setOSMFile(osmFile) is being called on a GraphHopper object while this function only exists in its subclass GraphHopperOSM.
Current (map matching):

GraphHopper hopper = new GraphHopper();
hopper.setOSMFile("./map-data/leipzig_germany.osm.pbf");

Current (Routing via Java API in graphhopper/docs/core/routing.md)

GraphHopper hopper = new GraphHopperOSM().forServer();
hopper.setOSMFile(osmFile);

Possible solution:

GraphHopperOSM hopperOSM = new GraphHopperOSM();
hopperOSM.setOSMFile(osmFile);
GraphHopper hopper = hopperOSM.forServer();

My apologies if I am simply misunderstanding or overlooking something.
Thank you!

That is correct and is already fixed :wink:
Thanks for pointing this out!

1 Like

Ups, this was not properly fixed (will do in a sec) … we need a compiler for the docs https://github.com/graphhopper/graphhopper/issues/774#issuecomment-246299037 Maybe someone knows a solution for this?

It does indeed seem that a compiler for the docs would be very useful, the map matching constructor used in the example seems to be outdated:

GraphHopperStorage graph = hopper.getGraphHopperStorage();
LocationIndexMatch locationIndex = new LocationIndexMatch(graph,
(LocationIndexTree) hopper.getLocationIndex());
MapMatching mapMatching = new MapMatching(graph, locationIndex, encoder);

Instead this should probably be something like this?

String algorithm = Parameters.Algorithms.DIJKSTRA_BI;
Weighting weighting = new FastestWeighting(encoder);
AlgorithmOptions algoOptions = new AlgorithmOptions(algorithm, weighting);
MapMatching mapMatching = new MapMatching(hopper, algoOptions);

1 Like

Thanks for finding this (will have a look), would love to have a proper solution, but see the issue - it does not seem to be that simple.