Cannot read own "-gh" files - Exception in thread

Dear all,

First, let me thank you for this wonderful software! It’s really amazing! My problem (most likely trivial, but I’m not very good in writing Java code…): Several years ago I managed to write my own code for version .03 which loads a map, some geo locations from another file, do the routing and write the result to a third file. After moving to Win 10 with VM (Ubuntu 18.04), I have troubles getting the code running again.

I followed the instructions found here which worked fine for version .13. I can download maps, start ./graphhopper and do some routing in the browser at localhost. Doing so also leaves the “-gh” directories behind which I would like to read and use for working (see above).

However, when doing so, I get the following message:
Exception in thread “main” java.lang.IllegalStateException: Encoded values do not match:
Graphhopper config: roundabout|version=283388307|bits=1|index=0|shift=0|store_both_directions=false
Graph: roundabout|version=283388307|bits=1|index=0|shift=0|store_both_directions=false,road_class|version=888755028|bits=5|index=0|shift=1|store_both_directions=false,road_class_link|version=146075245|bits=1|index=0|shift=6|store_both_directions=false,road_environment|version=-446726394|bits=3|index=0|shift=7|store_both_directions=false,max_speed|version=-1300485567|bits=5|index=0|shift=10|store_both_directions=true,road_access|version=-313723172|bits=4|index=0|shift=20|store_both_directions=false
Change configuration to match the graph or delete /home/defferl/graphhopper/gh13GG/…/…/winShare/ArbeitOhneSync/OSM/zlinMai2020-gh/
at com.graphhopper.GraphHopper.load(
at gh13GG.main(

I soon found someone who had a similar problem. Unfortunately, I could not get the code running (I use the jars, which help me a lot, since my Java-experience is very limited).

My code so far is pretty short, it boils down to:

import com.graphhopper.GraphHopper;
import com.graphhopper.routing.util.EncodingManager;
import java.util.ArrayList;
import java.util.List;

public class gh13GG {
    public static void main(String[] args) {

        final EncodingManager carEncoder = EncodingManager.create("car");
        GraphHopper gh  = new GraphHopper().setEncodingManager(carEncoder);
        String ghLoc = "../../winShare/ArbeitOhneSync/OSM/";
        String currentArea = "zlinMai2020"+"-gh";
        System.out.println(new File(ghLoc, currentArea).getAbsolutePath());
        boolean b = gh.load(new File(ghLoc, currentArea).getAbsolutePath());

Is there something wrong with setting up he Graphhopper-instance? Thanks very much in advance. I’m also sorry for the most likely strange format of the text.


Hiya, some suggestions

Ensure that you remove all old version of graphs that you might have created in the past, they will not translate correctly across different versions. If you change your configuration you most likely will have to rebuild the graph as well.
Before loading you can gh.clean(); to ensure any previous graphs are removed. You only would want to do this once when changing versions or settings as importing a prebuilt graph is a lot faster.
I use a button in an options menu to allow users to clear the graph and rebuild on run.
I use gh.importOrLoad(); unsure if that would suit better than your gh.load();

Dear Greg,

Thanks very much for the quick reply and suggestions. Unfortunately I only had a few minutes to try your suggestions, as my boss kept me busy with other work… At least within this short time I could not get ahead.

At home I tried GH on my native Linux installations, but to my astonishment I ran into other troubles on both systems: exactly like the ones described here, but the solutions described there did not work for me. I did not want open another thread yet, as I still want to try it on my own…

Again many thanks, best,

The output from your logs states
“Change configuration to match the graph or delete /home/defferl/graphhopper/gh13GG/…/…/winShare/ArbeitOhneSync/OSM/zlinMai2020-gh/”
Delete your already created graph files, insure you use gh.importOrLoad();
Can you please post your changed code and double make sure no existing graphs exist in the folder paths you use.

1 Like

Thanks very much! I had to try quite a bit, but finally I managed to get the code running. There were several nasty error-messages, but with Karusell’s answer here (using new GraphhopperOSM()) in combination with your hints I was successful. Here’s the code:

import com.graphhopper.GraphHopper;
import com.graphhopper.reader.osm.GraphHopperOSM;
import com.graphhopper.routing.util.EncodingManager;

public class gh13_try {
    public static void main(String[] args) {
        System.out.println("Hello, World tester!");

        final EncodingManager carEncoder = EncodingManager.create("car");
        GraphHopper gh  = new GraphHopperOSM().setEncodingManager(carEncoder);
        String ghLoc = "../../winShare/ArbeitOhneSync/OSM/";
        String currentArea = ghLoc + "malta-latest.osm.pbf";
        System.out.println(new File(ghLoc, currentArea).getAbsolutePath());

I’m fully happy with this, but when trying to get a perfectly clean installation of GH that new one did not show the map in the browser when calling “./ -a web -i europe_germany_berlin.pbf”, just the start and stop locations etc. Is 0.13 still developed and could some of those version be unable to show the map for some reason? As I said, my code works now and I can continue with that.

Many thanks again and probably until soon…!

Ah, sorry I missed that in your code. Glad you got it working for yourself.

GraphHopper graphHopper = new GraphHopper().setGraphHopperLocation(LocationGrapphopperFiles)
                .setEncodingManager(new EncodingManager("car"))
                .setElevationProvider(new CGIARProvider().setCacheDir(new File("C:/Users/elevationMyDearWatson/")))

This is how I use it and no longer have issues as long as I clear the graphs. Although I don’t view the map in browser so can’t answer your questions about that.

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