Modifying FootFlagEncoding to avoid/remove "Footpaths"

Hiya,

I’m wanting to use foot encoding but remove the use of footpaths and unsure how to go about it.
Currently;

GraphHopper graphHopper = new GraphHopper().setGraphHopperLocation(LocationGrapphopperFiles)
                .setEncodingManager(new EncodingManager("car,bike,foot"))
                .setOSMFile(LocationRoutingFile)
                .forDesktop();

This is so I can view routes for Car,Bike or Foot.
But for only foot I want to change safeHighwayTags.add("footpath"); to restrictedValues.add("footpath");
Where I get stuck is how to override FootFlagEncoder to remove specific HighwayTags.

Is anyone able to provide some insight of what I should be doing to remove the use of footpaths?

Cheers,

For 1.0 you can use the custom weighting:

priority: { road_class: { track: 0 } }

Thanks for the info.
I searched through and couldn’t find docs on implementing the config.yml profile.
Am I correct in thinking that graphHopper.init(new GraphHopperConfig(new PMap("/path/to/config.yml"))); is the way to set it up in java?

Also to make sure that if using the config file I don’t have to set things like graph location, elevation etc as these are set within java.

GraphHopper graphHopper = new GraphHopperOSM().setGraphHopperLocation(LocationGrapphopperFiles)
                .setEncodingManager(encodingManager) 
                .setDataReaderFile(LocationRoutingFile)
                .setElevation(true)
                .setElevationProvider(new CGIARProvider().setBaseURL("C:/Users/elevation/"))
                .setProfiles(Arrays.asList(
                    new Profile("foot").setVehicle("foot").setWeighting("fastest"),
                    new Profile("custom_foot").setVehicle("foot").setWeighting("custom"),
                    new Profile("bike").setVehicle("bike").setWeighting("fastest"),
                    new Profile("car").setVehicle("car").setWeighting("fastest")))
                    .forDesktop();
            //graphHopper.init(new GraphHopperConfig(new PMap(LocationGrapphopperFiles+"/config.yml")));
            graphHopper.importOrLoad();

So the custom_foot profile is read from the config.yml, which references

profiles:
  - name: custom_foot
    vehicle: foot
    weighting: custom
    custom_model_file: path/to/my_custom_profile.yml

Which then uses priority: { road_class: { track: 0 } } ??
Or by setting the config.yml it means I no longer need to .setProfiles and just set them up within the config instead?

For Java you do not need to load the config.yml file and can do everything with “objects”. See e.g. CustomWeightingRouteResourceTest on the configuration (using CustomProfile).

Thanks mate.

Currently testing the following;

GraphHopper graphHopper = new GraphHopperOSM().setGraphHopperLocation(LocationGrapphopperFiles)
        .setEncodingManager(encodingManager) 
        .setDataReaderFile(LocationRoutingFile)
        .setElevation(true)
        .setElevationProvider(new CGIARProvider().setBaseURL("C:/Users/Elevations/"))
        .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("paxster").setCustomModel(new CustomModel()).setVehicle("foot").setWeighting("custom").putHint("custom_model_file", RouteToMap.class.getClassLoader().getResource("paxster.yml").getFile())))  
        .forDesktop();

With paxster.yml being

priority: { road_class: { footway: 0 } }

Unfortunately footpaths are still being used.
Issue being;
image

Hints set as per CustomWeightingRouteResourceTest

System.out.println(graphHopper.getProfile("paxster").getHints());
{custom_model=distanceInfluence=70.0|speedFactor={}|maxSpeed={}|maxSpeedFallback=null|priorityMap={}|areas={}, custom_model_file=C:/Users/mavenproject2/target/classes/paxster.yml}

If I try to setup the profiles exactly the same as the test file I get
Something went wrong with GH
CustomModel cannot be null

Really stuck on this :frowning:
What is going wrong? The way I’m setting up the profile allows me to use the “paxster” profile but it is still using footpaths.
Do I need to setup anything in the routing request other than to use “paxster”?

You cannot load the profile from file they way you did. See GraphHopperManaged on how we do it:

CustomModel customModel = (customModelLocation.endsWith(".json") ? jsonOM : yamlOM).readValue(new File(customModelLocation), CustomModel.class);
                    newProfiles.add(new CustomProfile(profile).setCustomModel(customModel));

Or better create the CustomModel via Java:

CustomModel model = new CustomModel();
HashMap map = new HashMap();
map.put("footway", 0);
model.getPriority().put("road_class", map);

For playing around I recommend to use GraphHopper Maps and the input text box instead of a file-based approach that requires a re-import. See our recent blog posts about this new feature:

There you will also see how to enable the path details which gives you information about e.g. the road_class property along the path. With that information you can also be sure to use the correct name to pick it for avoidance.

E.g. have a look into this link: http://148.251.46.152:8989/maps/?point=40.837276%2C-73.900239&point=40.836014%2C-73.898538&details=road_class&debug=true&layer=OpenStreetMap&vehicle=foot

You should see this:

(due to some bug you now need to click on the foot icon otherwise you’ll get an error in the next step)

Now when you click on the “flex” button near the search button and enter your custom model into the opened text input:

priority: { road_class: { footway: 0 } }
details: [road_class]

You’ll get:

(the colors are not stable and so it comes the violet can have a different meaning in every route)

1 Like

Thankyou!!

I did play around with the Flex that you setup and it worked great. I looked through all sorts of docs but I couldn’t find the correct method to set it in Java. I’m by no means an expert in Java as I have just started learning it.

This has resolved my issue of erroneous footpaths not being connected on a country wide level.

I appreciate your time.

1 Like

Thanks for the update. The documentation for the Java part is surely suboptimal, but as the feature is intended for users without Java skills that makes sense :slight_smile:

Still if something is not well documented you can always have a look into our tests. Every feature has a test coverage somewhere and so the usage via Java is always shown there even if it is not documented.

Yeah, I always look through the tests to see how stuff has been implemented but I find myself getting stuck as I did with CustomWeightingRouteResourceTest
putHint("custom_model_file",RouteToMap.class.getClassLoader().getResource("paxster.yml").getFile()
Especially as you mention for features intended for different implementations.

There is something in some routes causing the route to fail. I’m guessing its unable to calculate the path between some points with priority footpath = 0.
It works fine with car and foot base profiles. Is there anything to get around this issue? I’ve tried setting the priority for footpath very low but it will still use the footpaths that mess things up.
Is it a case of trying and if error then use a different profile?

Ah, ok. This test is still using the web service and so this can work because GraphHopperManaged is called: graphhopper/web-bundle/src/main/java/com/graphhopper/http/GraphHopperManaged.java at master · graphhopper/graphhopper · GitHub

I’m guessing its unable to calculate the path between some points with priority footpath = 0

if you e.g. exclude ferries and have two islands only connected through a ferry then it won’t find a route.

Do you have an example that works on the custom routing demo server that has this problem?

I will investigate further to assess which path is causing the issue. As of now there are over 1000 points mapped (not a huge area though) and from the looks of it, it seems to be a footpath that is going along side an express way but I have to be sure.

[com.graphhopper.util.exceptions.ConnectionNotFoundException: Connection between locations not found]

I limit to 1084 points and it works fine, limit to 1085 and it fails.

Between 1084 - 703/26 Library Lane -36.7265512372916, 174.696570519881
and 1085 - 7 Rose Garden Lane -36.7254772797197, 174.70740666905
[com.graphhopper.util.exceptions.ConnectionNotFoundException: Connection between locations not found]

Note that Rose Garden Lane is a service lane. So adding;
priority:
road_class:
service: 0.1
footway: 0
Still results in Connection between locations not found

This is how a car reaches there - why does no pathing want to use rose garden lane? It has assumed 2 way, all vehicles are allowed access, surface is asphalt. It does have a speed hump though, would that impact it?

Can you try with a low value for footpath that still works and additionally display the road_class details via:

details:[road_class]

Then you should find the footpath that is causing the disconnection

Can you try with a low value for footpath that still works? And additionally display the road_class details via:

details:[road_class]

Then you should find the footpath that is causing the disconnection

Thanks Peter,

The first part of Rose Garden Lane on the right is unnamed service type.
Something to note; adding the local MVT layer shows it stops when going down the service lane;
image

So can walking be allowed to reach the point from a far away point as the car profile does? This would hopefully eliminate future issues.

Edit
I updated my PBF and everything seems to be fine now. Thanks for your help, I will be able to self diagnose more next time :slight_smile:
image

1 Like