GraphHopper.com | Forum | GitHub | Maps | Blog

Load custom weights from multiple external sources


#1

I was wondering which is the best strategy to load custom weights from multiple sources. In other words, I have a set of files that associate OSM ids with custom weights, the goal would be to load them in addition to the standard OSM data.

For example let’s imagine that I have a map between OSM wayID -> custom_weight_1 and I want to make available to my weighting class, let’s say an extension of the FastestWeighting, not only the speed but also the custom_weight_1 for each edge. How should I approach the problem?

Thanks!


Create custom vehicle
#2

Look at the DataflagEncoder :slight_smile: You can save additional information for each wayId in the flags with EncodedValues. So the strategy would be: Save your information in an encodedValue per wayId. In the weighting, you get the flags of each edge. With the flagencoder and the getValue(long flags) you can use the saved information for the weighting.


#3

Thanks a lot for the quick answer. Loading the customized weights should be done modifying the OSMReader class or is there a better approach?

(sorry for the naive questions!)


#4

You can load the modified weighting in the GraphHopper class. Look at the createWeighting function :slight_smile:


#5

Do you mean I should open and load my custom csv file with the pairs (osm_wayid_1, custom_weight_1) in the Weighting class?


#6

As you are not getting the wayId(edgeId !=wayId) in the weighting class, you should save them in the flagEncoder.


#7

thanks for the tip! I got the pipeline almost working creating a custom weighting and a custom FlagEncoder where I load the custom weights from a file. The problem is that I couldn’t find a lot of information on how to encode correctly these weights without messing up with the weights that are already there.

For example, I extended the FootFlagEncoder and I would like to add a double to an edge flags, how should I approach the problem (e.g., how I deal the offset and similar). Do you know of any detailed tutorial/working example on this?

Thanks!


#8

An example is in the DataFlagEncoder. You just create an EncodedValue and the setValue(long flags, long value)-Method will take care of the flags. So in your FlagEncoder is just a call:

flags = yourEncodedValue.setValue(flags,valueToSet);

Also the getValue() method just takes care of extracting the value later out of the edge flags.

In the DataFlagEncoder look at the methods defineWayBits(int index, int shift) and handleWayTags(ReaderWay way, long allowed, long relationFlags). It should give all information about how to create an EncodedValue, initialize it and how to set values :slight_smile: I don’t have a tutorial, sorry. Just look at the methods and I’m happy to answer your questions :slight_smile:

I hope it helps.


#9

Thanks a lot for your help, I still have a lot to learn and bits that I don’t fully understand, but I managed to make it work! :wink:


#10

No problem :slight_smile: I like to help others if I can. Do you have any questions about what you don’t fully understand?