Is there a doc/example for using GraphHopper for batch processing a large number of routes from command line, without web call overhead. Example use case: a large CSV file with start and end locations, for which time and distance estimates are required?

We just use it without the “.forServer()” (look into the method is just sets some things for you, isn’t needed locally or at all. You don’t build a server. You can just create a Class with a constructor that’s doing:

GraphHopper hopper = new GraphHopperOSM().forServer();
hopper.setDataReaderFile(osmFile);
// where to store graphhopper files?
hopper.setGraphHopperLocation(graphFolder);
hopper.setEncodingManager(new EncodingManager("car"));
// now this can take minutes if it imports or a few seconds for loading
// of course this is dependent on the area you import
hopper.importOrLoad();

and a function distance which has 2 paramaeters for your call and returns for example:

Just write a main for processing your csv and loop over all entrys and you will be fine. The graphfolder which is created just takes some time. (multiple hours if you need a big region, but it’s just a one time operation, loading an existing graph folder just takes seconds or minutes. It depends on your region size also)

The pbf file (called osmfile in the example) can you get from for example: https://download.geofabrik.de/ What regions do you need? Just a single country or more?

It all runs locally in your java environment. With a graphfolder in your memory something like 100ms per request.

@karussell What’s the .forServer() method good for? Is it better to use it everytime you run it on a server? Or is it just to set something like memstore? I didn’t notice any downside not using it, so I’m just interested.

This is something I was looking for for ages. Have anyone already created the code? I so, would you share it? (I can’t code in Java.) Or what would be the overhead if the server was accessed from Python or R (which I can code in)?

And by the way, can GraphHopper find the shortest route (not only fastest route) too?