# 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 http://stackoverflow.com/questions/29690820/in-graphhopper-how-can-i-retrieve-the-set-of-edges-contained-in-a-route

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

Thanks!

1 Like

`flagEncoder.getSpeed(edgeState.getFlags())`