Dynamic routing based on waytags

Hi all,

I’d like to add some dynamic routing into my android app by providing users the ability to avoid certain types of ways (i.e. steps) if they so choose. However, all the tags are stripped out from the edges during processing. I thought about encoding the type of way into a flagencoder, but I’m not really sure how that should be done or whether it would be better than actually setting up a database and storing the tags so that they remain for reference during the app execution.

Any tips? I’ve read some things online about storing things into flagencoders, but it seems rather difficult to figure out what these things are doing, where I should modify them, and what flags are actually needed in order for things to work correctly.

Thanks!

You can try the GenericWeighting which takes speeds for the different highway types. For that to work you need to disable CH and use the DataFlagEncoder (in config it is named generic)

Thanks! And just to clarify, what do you mean by “use the DataFlagEncoder”? Do I need to initialize the flags during preprocessing and then use them later in the GenericWeighting class? Also, does this mean I don’t need to use the method shown in https://github.com/graphhopper/graphhopper/blob/master/docs/core/weighting.md to create a custom weighting?

Yes, it should be possible without a custom weighting.

If you just want to try it out, the easiest way is to set graph.flag_encoders=generic in the config.properties and start the web server with:
./graphhopper.sh web your.pbf

and query with highways.residential=30 so e.g. http://localhost:8989/?point=52.462913%2C13.387871&point=52.529486%2C13.399372&vehicle=generic&weighting=generic&highways.secondary=35&highways.tertiary=30&highways.residential=30

There is not much documentation about this, but you can see this pull request: https://github.com/graphhopper/graphhopper/pull/730

So I’m actually not using the web server but rather the android offline version, so I’d be importing the pbf file. Also, where would the rest of that query go for android? (i.e. highways.secondary=35, highways.tertiary=30, etc.)

I’m actually not using the web server but rather the android offline version

Sure, but with the steps I suggested it is faster to understand the concept and see the results on a map.

where would the rest of that query go for android

As hints in the GHRequest

I’m really confused about the hints. How do you put them into the GHRequest? It seems like “highways.secondary” isn’t a valid argument. (i.e. this doesn’t work: req.getHints().put(highways.secondary, “30”);

Also, the request you gave me seems to not work when you set start and end points in locations that aren’t roads (i.e. getting routing from one building to another doesn’t work, but getting routing from a location on a highway to another location on a highway does), and for some reason I can’t get directions on pedestrian walkways, only highways. Are there any ways around these two issues?

Oh, actually putting it in quotes is valid. Still doesn’t seem to change anything on the app itself though.

Can you please try

req.getHints().put(highways.secondary, 30);

the request you gave me seems to not work when you set start and end points in locations that aren’t roads

What do you mean here? It should snap to closest road and then route between those snapped points

Oh, actually putting it in quotes is valid.

What do you mean here?

It gives me an error in android studio and says, “cannot find symbol variable highways.” Oh, I think it does snap to the closest road unless the closest road is considerably far away. (but either way, I want it to snap to footpaths instead of roads, but it doesn’t seem to be doing that?)

Sorry, it is a string:

req.getHints().put("highways.secondary", 30);

I want it to snap to footpaths instead of roads

Probably you have to enable these via highways.footway=5? If this still does not work, please create an issue.

Actually, what I meant by “putting it in quotes is valid” was that it’s a string. Sorry for the confusion. I tried highways.footway=5 on the web server but it still doesn’t work. I guess I’ll create an issue.

1 Like

Also, now it’s not working on android at all. What would this mean: “An error happened while creating graph:Configured graph.ch.weightings: [generic|generic] is not equal to loaded []”?

You’ll need to export the graphhopper data to android that you created on the desktop and configure the GraphHopper instance so that it matches the graph properties.

I don’t understand? I changed the config.properties file to match what works in the graphhopper web instance, and then I ran the graphhopper.sh on my osm pbf file. Then I transferred the files in the folder created by the shell script to my phone, but now it doesn’t work anymore. What do you mean by “configure the GraphHopper instance so that it matches the graph properties”? There doesn’t seem to be anything in the GraphHopper instance that I can change to reflect that I’m now using the generic flag encoders.

Hi, sorry to bring this up again, but I still haven’t been able to figure out why it’s not working. I believe I have configured the GraphHopper instance so that it matches the graph properties, as seen below:
GraphHopper tmpHopp = new GraphHopper().forMobile();
tmpHopp.setEncodingManager(new EncodingManager(“generic”));
tmpHopp.setCHEnabled(false);
tmpHopp.load(new File(mapsFolder, currentArea).getAbsolutePath() + “-gh”);
log("found graph " + tmpHopp.getGraphHopperStorage().toString() + “, nodes:” + tmpHopp.getGraphHopperStorage().getNodes());

When the app loads, it says in the log:
found graph generic|MMAP_STORE|2D|NoExt|5,14,4,3,3, nodes:448065

So I’m assuming it loaded correctly. But whenever I try to find a path between two points on a footpath, it doesn’t work (even if it’s the same footpath, so I’m sure there must be a path):
Error:[com.graphhopper.util.exceptions.ConnectionNotFoundException: Connection between locations not found]

This only happens for the android mobile app, while the web app is fine and actually finds the connection. Is there something else I’m missing?

Please, can someone answer this question? This project is due in two days and I really would like to get it working. Thanks!

Are you sure? Currently foot support needs customization for the generic weighting as we discussed under 881

Right, basically I changed the dataflagencoder to only accept certain highway tags, so now it works on footways on the web server. For some reason though, it still doesn’t work at all on mobile.