Recomended Way to Extend Graphhopper


#1

What would be the recommended way to extend GraphHopper? I.e. add a new FlagEncoder with a custom Weighting class.

I’ve been looking at replicating the structure from OpenRailRouting, but I think that is too much for just adding a new profile.

I am currently using the custom FlagEncoder and Weighting with:

public class RoutingExample {
    public static void main(String[] args) {
        GraphHopper hopper = new CustomHopper().forServer();
        hopper.setCHEnabled(false);
        hopper.setDataReaderFile("data/austria-latest.osm.pbf");
        hopper.setGraphHopperLocation("data/austria-gh");
        
        FlagEncoder encoder = new CustomFlagEncoder();
        hopper.setEncodingManager(EncodingManager.create(encoder));
        
        hopper.importOrLoad();
        
        GHRequest req = new GHRequest(47.811195, 13.033229, 48.210033, 16.363449).
                setWeighting("custom_weighting").
                setVehicle("custom_encoder").
                setLocale(Locale.US);
        
        GHResponse rsp = hopper.route(req);
        System.out.println(rsp);
    }
}

and with the graphhopper-core and graphhopper-reader-osm maven repositories in the pom file. But I would like to also use the server as an API with the new routing profile. I was thinking to either include Graphhopper as a git submodule or add the appropriate maven repositories (graphhopper-web maybe?)

What would you recommend? Is there an example for this? I am happy to create a simple hello world template as a starting point if there is nothing yet in this direction.


#2

For example you can just implement it in a spring boot application where you get an api call to some endpoint and so you can call graphhopper the way you want it (for example with custom weighting and the flagEncoder you want to use.


#3

Is there a way to use the Graphhopper Web API with a custom routing profile instead of rolling my own? I am not to fresh on Maven, but can I use the graphhopper-web or graphhopper-web-bundle repository maybe?


#4

As an example see our map matching module: https://github.com/graphhopper/map-matching/blob/master/matching-web/src/main/java/com/graphhopper/matching/http/MapMatchingApplication.java


#5

I managed to create a minimal working example: minimal-graphhopper I hope it is a useful starting point. Would you add something to that or have some things that could be improved in the structure of the code?

Also, I assume that create-new-flagencoder.md needs to be updated since as far as I understood I needed to update DefaultFlagEncoderFactory instead of adding the new FlagEncoder to EncodingManager.parseEncoderString.

The API works now fine, but I experience two issues when running the routing in the browser:

  1. If I select two points, the routing works. But if I first press on one of the encoders I get No area description found and I cannot select points until I reload the page back to localhost:8989. Am I missing something?
    image

  2. Is there a simple way in my minimal example for the new FlagEncoder to have its own symbol (or reuses another symbol) in the browser?