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:
DoubleEncodedValue speedEnc = encoder.getAverageSpeedEnc();
double fwdSpeed = edge.get(speedEnc);
double bwdSpeed = edge.getReverse(speedEnc);
This speed is used to calculate edge weights, yes. For example see