Hello! I’m trying to calculate shortest path for different vehicle types but avoiding some road classes and environments (eg motorways, toll roads, etc). I’m running an instance of GH locally but the API doesn’t seem to actually avoid the different keywords I’m passing. I saw on a different thread that this feature is only available in the commercial version (but that comment was quite old). Could anyone confirm if that is still the case?
On a related issue, is it possible to avoid road classes and environments when calculating isodistances? I couldn’t find this option when checking the docs. If this is not possible, I’m assuming the only solution to calculate isodistances whilst avoiding motorways, tolls, etc is to write my own version of it using the routing API?
// Exclude footways, stairs from profile
CustomModel model = new CustomModel();
HashMap map = new HashMap();
map.put("footway", 0);
map.put("steps", 0);
map.put("service", 1.0);
model.getPriority().put("road_class", map);
Then as you set the profiles;
graphHopper = new GraphHopperOSM().setGraphHopperLocation(locationGrapphopperFiles)
...........................
...........................
.setProfiles(Arrays.asList(
new Profile("foot").setVehicle("foot").setWeighting("fastest"),
new Profile("bike").setVehicle("bike").setWeighting("fastest"),
new Profile("bike2").setVehicle("bike2").setWeighting("fastest"),
new Profile("car").setVehicle("car").setWeighting("fastest"),
new CustomProfile("name_of_your_profile").setCustomModel(model).setVehicle("foot").setWeighting("custom")))
So the footway is set to 0 which disables it and service 1.0 to enable it.
To enable private access for private roads; EncodingManager encodingManager = EncodingManager.create(FlagEncoderFactory.FOOT + "|block_private=false,
Hi @Gregws! Thank you very much for your answer. Have it working now… apart from avoiding toll roads. Can’t see tolls being any under a custom model (and I believe the example yml in the repo have toll inside “priority” but that doesn’t seem to be correct…) Many thanks!!
Hi again @Gregws! Thank you very much for taking the time to reply! Unfortunately, I’ve already tried what you suggested but it doesn’t like it Error: Cannot find encoded value 'toll' specified in 'priority'. Available: roundabout,road_class,road_class_link,road_environment,max_speed,road_access I read through the code in the repo and I can’t quite see any reference to tolls in the custom models so wondering if that’s not really possible.
I’m able to replicate the behaviour you are describing using flex and the maps service, but I’m trying to do everything programmatically against the Routing API (as I need to calculate shortest distance for a large number of locations, but also using some customisation like no tolls, no motorways, etc). Not very successfully so far unfortunately (and using &avoid=toll in the request doesn’t seem to do the trick. Would you happen to know if I could use flex programmatically against Routing API?
Sadly I also tried that but it didn’t like it either Error: Cannot find enum toll in [other, road, ferry, tunnel, bridge, ford, shuttle_train] Reading through the code, tolls don’t seem to be in any of the custom profiles so might not be possible Thanks for your very kind help @Gregws!!
You add toll to the graph.encoded_values in the config.yml (reimport required after that!) and then you can use it how @Gregws said in the first post via toll: no (without road_environment)
Thank you so much for all the help, really appreciate it!! I’m almost there I believe. Now, I’m trying to write some tests to double check the paths I’m getting are correct. I’m not spinning the API, just querying the JAR and I would like to get the details of the path (e.g road class, road environment, etc). I’ve got here
But the path details (the place I was assuming I would find all those details) seems empty in both GHRequest and ResponsePath. Am I missing something in the config to get those bits populated?
The bit I’m struggling to get working in Java (fine when querying the API) is to get details about toll roads. I thought this would do but it doesn’t like it
GraphHopper hopper = new GraphHopperOSM().forServer();
hopper.setDataReaderFile(osmFile);
hopper.init(new GraphHopperConfig().putObject("graph.encoded_values", "road_class, ...,toll"));
// then
GHRequest req = new GHRequest(latFrom, lonFrom, latTo, lonTo)
.setProfile(profile)
.setPathDetails(Arrays.asList("road_class", "road_environment", "toll"));
Getting You requested the details [road_class, road_environment, toll] but we could only find [road_class, road_environment] so I’m assuming the way I do GraphHopperConfig()... is not quite correct. Any clue why that might not be working? Thanks so much!
It’s working now! I was stupidly overwriting the EncodingManager so killing the config. Just in case anyone might find this useful, I’m attaching a small snippet of code;
Happy to give it a try if that helps people. Also, haven’t done Java in a while so my code might need many, many code reviews Thanks again for your help!!