How to get speed and distance of each edge in a Path?

I’m trying to calculate the cost of a trip, which depends on the distance and speed of each edge. Now seems like I should override Graphhopper route method and do the calculation form paths that is returned by calcPaths. It seems the Path object contains the edges(edgeIds). The ShortestWeighting#calcWeight kind of demonstrates what I want from a EdgeIteratorState object, but I’m not sure how to get this from the Path object.

Can anyone help me regarding this?

Do you want to change the weighting via including time and distance? Or do you want to calculate the weight after e.g. the fastest path was calculated (where only time is considered)?

Thanks for helping. I want to calculate the weight after the fastest(or shortest) path was calculated.

You can then create a subclass of GraphHopper and intercept the calcPaths method where you can e.g. feed the GHResponse.hints with the information based on the edges.

Yeah, I got that part. I see the edgeIds in the Path objects, but I’m not sure how to get the speed and distance from them.

I found what I was looking for. Path::calcEdges() gives me what exactly want.

1 Like

I would be interested in the answer.
I need similar information to calculate the time to go through a path with a special weighting.
I follow an idea based on

So, I am also using Path::calcEdges().
However, how can we determine the direction of the edges returned by calcEdges()? (the boolean reverse?)
I need this information because the my special weighting depends on that.

So far, i can determine which by which node start the path (with Path::calcPoint and LocationIndex::finbdClosest() ).

However, i would like to know if there is a more “elegant” solution


1 Like

In the weighting you have access to the flagEncoder. Then do


or extend the FastestWeighting where the time is already properly calculated.

See this issue for future usages we eventually plan

I need this information because the my special weighting depends on that.

You can check adjNode and baseNode

1 Like