Is it possible to provide GraphHopper a csv file with custom speed limit for all the edges of the graph? I mean, after extracting the speeds of the GraphHopper graph in a csv file and assign my custom values to all the edges, and then provide that csv file to GraphHopper again and use the new speed for route calculation?
I’m not sure what you are trying to do. You said you first want to extract speeds from GraphHopper to csv, but then assign different values and then import the speeds again? And are you using the latest (master) version or e.g. 8.0?
It is for experimental purpose. I want to assign specific speed to specific roads and see how the route change. I implemented 'AllEdgesIterator" to get details about the all the links in the graph. Now I want to reassign my custom values to specific links in that csv and import the speeds again to GH. I am using version 8.
If you run the import again the edges should have the same IDs. So you should be able to implement a TagParser, something like this:
public class CustomCsvSpeedParser implements TagParser {
private double[] csvSpeeds;
private DecimalEncodedValue speedEnc;
public CustomCsvSpeedParser(DecimalEncodedValue speedEnc) {
csvSpeeds = readCsvSpeedsFromFile();
this.speedEnc = speedEnc;
}
@Override
public void handleWayTags(int edgeId, EdgeIntAccess edgeIntAccess, ReaderWay way, IntsRef relationFlags) {
// note that GraphHopper generally uses two different speeds depending on the direction (but very often they are the same). this is ignored here since we only use one speed per edgeId
speedEnc.setDecimal(false, edgeId, edgeIntAccess, csvSpeeds[edgeId));
}
}
Add this tag parser to DefaultTagParserFactory and make sure it is activated on your second import in GraphHopper.java/buildOSMParsers.