I want to integrate offline traffic data into routing engine. I saw demo example, but I’m not sure that I understand everything correctly.

For what I can understand, while GH imports data for example from OSM, he builds flags for every edge? But we can have multiple encoders, so how does it work? Every encoder has his own graph?

The second thing is edge direction. I saw that, it can be forward/backward. Let’s say I’ve got path from point A to point B, with average speed about 25 km/h, and in reverse from B to A speed is 20 km/h. How can I know which value I should set in edge forward or backward. I simply have path with points and speed associated with them.

One last question. Encoders provide method getSpeed, is this method invoked only in import process? Or is also used to calculate some weighting?

For what I can understand, while GH imports data for example from OSM, he builds flags for every edge? But we can have multiple encoders, so how does it work? Every encoder has his own graph?

Yes, GH stores ‘flags’ for every edge. You can think of this as some efficiently stored meta data. When there are multiple encoders this just means that different data is stored for each encoder (for the same edge). Every encoder might store its own data in flags, but they all use the same graph. Some of the meta data is shared between multiple encoders. For example every edge has only one value for ‘road_class’, but there are separate values for ‘average_speed’ for each encoder.

GraphHopper’s ‘forward’ direction is the direction of the path according to the OSM node IDs of the corresponding way. So you are saying you have ‘paths’? Do you mean you have an array of GPS coordinates and a corresponding speed? Then you first need to figure out which GraphHopper edges correspond to this path (how do you do this?) and of course you also need to figure out the direction your path uses the GraphHopper edges. For example when you know your path includes GraphHopper edge number 458 from GPS point A to GPS point B you can do something like

NodeAccess na = graph.getNodeAccess();
// gets the edge in storage direction, so the forward speed will correspond to base->adj and the backward speed will correspond to adj->base
EdgeIteratorState edge = graph.getEdgeIteratorState(458, Integer.MIN_VALUE);
int base = edge.getBaseNode();
int adj = edge.getAdjNode();
double baseLat = na.getLat(base);
double baseLon = na.getLon(base);

to figure out whether you need to set the forward or backward speed.

Not sure what you mean. There is no FlagEncoder#getSpeed() method. There is FlagEncoder#getAverageSpeedEnc() which can be used like this: