LocationIndex does not return Closest Node/Edge for Custom Graph

We are using the Low Level API and have created a custom graph from our own Maps data. The Graph nodes have Latitude and Longitude data while the edges have our custom edge weights (defined by the Cost incurred to traverse that edge).

We are successfully able to get the Shortest Path (Dijkstra) between any two Nodes on the Graph. However when we provide a Point location (Lat/Long) then we are not able to get the Nearest Node (returns -1)/Nearest Edge (returns NULL) on graph using the Location Index. We have verified that the points provided by us are nearby some of the nodes on Graph (i.e. Distance << MaxRegionSearch*Resolution).
Code snippet below:

LocationIndex index = new LocationIndexTree(graph.getBaseGraph(), new RAMDirectory(graphFolder, true));
index.setResolution(res);
((LocationIndexTree) index).setMaxRegionSearch(50);
if (!index.loadExisting()) 
    index.prepareIndex();
return index.findClosest(lat, lon, EdgeFilter.ALL_EDGES);

Kindly help with what could be the issue?

I’m missing the question here :wink: … but you probably want to know what is wrong … that is not really possible to say since you customized GH core. Make sure LocationIndexTree is properly feeded and prepareIndex is actually called and so the index is created from the edge data.

Thanks for the reply Peter.
The Graph is correctly feeded to the LocationIndexTree object: Sure because the same Graph object is calculating the Shortest Path correctly.
prepareIndex is also positively called: Sure because its printing on the console as well as location_index file is getting created.

Can you help us what is the best way to go about debugging this issue?

PS:

My bad: it somehow did not get copied from my Text editor :slight_smile:

The problem could be anything and I fear I won’t be able to help here more except to recommend you debugging and comparing with the OSM data import

Sure

Issue resolved. There was no problem after all. The latitude/longitude data was messed up a bit.
Thanks a lot.

1 Like