Get list of edges id from response path

Hi everyone,

I have a ResponsePath coming from the following code:

GHRequest req = new GHRequest();
//Modifies request using methods
GHResponse rsp = hopper.route(req);
ResponsePath path = rsp.getBest();

Now I can easily retrieve the PointList:

PointList pointList = path.getPoints();

But I also need the list of ids involved in the path whithout using the LocationIndex for each intermediate node.

LocationIndex locationIndex = hopper.getLocationIndex();
Snap qr = locationIndex.findClosest(longitude,latitude, EdgeFilter.ALL_EDGES);
int edgeId = qr.getClosestEdge().getEdge();

Is there any simple way to get that data directly from the response?
Please note that path.getLegs() returns an empty list

Thank you in advance

You can use

// ...

I just added this to the examples here:

1 Like

Many thanks, it works!

Is there any way to use the OSM_ID intead of the ids created by GraphHopper?

No you cannot use the OSM way IDs instead of GraphHoppers internal IDs. Currently even attaching them as meta-data is not implemented. Of course it is possible to do this, but it requires some modifications of the code. Use the forum’s search functionality. This question has been asked many times I think. The best approach might be creating an encoded value for the way IDs, then it should be easy to retrieve the OSM way IDs for a calculated route using the path details approach (if this is what you want to do). For example have a look here: Change speed for certain vehicle profile

1 Like
Powered by Discourse