Graphhopper 0.13 new custom profile class

Dear community,
i want to implement a new profile class into gh 0.13 version for my study. i created a new class, i added it in the defaultflagencoderfactory and flagendcoderfactory but when i strart the app on my device, it automaticly uses the car profile. Any hints where can i change this or what i else have to do?

With best regards
Chamflo

Code Snippet:

void loadGraphStorage() {
logUser(“loading graph (” + Constants.VERSION + ") … ");
new GHAsyncTask<Void, Void, Path>() {
protected Path saveDoInBackground(Void… v) throws Exception {
GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.setEncodingManager(EncodingManager.create(new CustomEncoder(4,2,0)));
//tmpHopp.setEncodingManager(EncodingManager.create(FlagEncoderFactory.CUSTOM));
//tmpHopp.setEncodingManager(new EncodingManager( “custom” ));
//EncodingManager encodingManager = EncodingManager.create(new CustomEncoder());
//tmpHopp.setEncodingManager(encodingManager);
tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath() + “-gh”);
//tmpHopp.init(new CmdArgs().put(“graph.flag_encoders”, “custom”).put(Parameters.CH.PREPARE + “weightings”, “no”));
//tmpHopp.importOrLoad();
log("found graph " + tmpHopp.getGraphHopperStorage().toString() + “, nodes:” + tmpHopp.getGraphHopperStorage().getNodes());
hopper = tmpHopp;
return null;
}

        protected void onPostExecute(Path o) {
            if (hasError()) {
                logUser("An error happened while creating graph:"
                        + getErrorMessage());
            } else {
                logUser("Finished loading graph. Long press to define where to start and end the route.");
            }

            finishPrepare();
        }
    }.execute();
}

Update:
Where can i change the default profile to my custom profile or how do i change the code above to use my profile. The commented lines are different tries but every time another exception appears. For example “FlagEncoder not yet initialzed”, “FlagEncoder does not match” or “No configuration changes are possible after loading the graph”. If I should be more specific about anything just ask and i’ll try to answer properly.

Kind regards
Chamflo

Update:

Current Error Message:
An error happened while creating graph:Encoding does not match:
Graphhopper config: custom|speed_factor=2.0|speed_bits=4|turn_costs=false|version=2
Graph: car|speed_factor=5.0|speed_bits=5|turn_costs=false|version=2
Change configuration to match the graph or delete /storage/emulated/0/Download/graphhopper/maps/europe_germany_berlin-gh/

Deleting does not fix the problem!

Do i need to make changes in config.yml?
Still anything wrong in the code above?
And i still dont know where the profile car is defined as default profile… nowhere named as far as i read through the files

Kind regards
Chamflo

My use case:
EncodingManager.Builder emBuilder = new EncodingManager.Builder(16);
// flag_encode
if (!StringUtils.isEmpty(graphHopperConfig.getGraph().getFlagEncoders())) {
emBuilder.addAll(new RouteFlagEncoderFactory(), graphHopperConfig.getGraph().getFlagEncoders());
}
// encoded_values
if (!StringUtils.isEmpty(graphHopperConfig.getGraph().getEncodedValues())) {
emBuilder.addAll(graphHopperOSM.getTagParserFactory(), graphHopperConfig.getGraph().getEncodedValues());
}
graphHopperOSM.setEncodingManager(emBuilder.build());

Can you please use code formatting? Otherwise the code is very hard to read. Either use the ‘preformatted text’ icon or wrap your code in triple backticks (```) like this:

public class MyCode {
   public int myMethod() {
      System.out.println("hello");
  }
}

Then, why do are you still using version 0.13? It makes it harder to answer you questions for such older versions, because first for us developers it is hard to remember all the details for every version and second some problems might already be fixed by now.

@Chamflo:

Depending on the version you are using you can either use the vehicle or profile request parameter to choose a profile for each request. But since I do not see any request in your code I am not sure if this answers your question.

This can only happen if you somehow did not delete the right folder.

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