Check if 2 paths intersect

Hi there,

First of all, thanks for building such a great tool!

Now, the question: Assuming that I have 2 PathWrapper objects, is there any easy way to check whether the 2 paths intersect?

Thank you,
Vladimir

This is only possible via using the GPS coordinates of the PathWrapper.

If you use the GraphHopper.calcPaths method you have access to the edge ids and check if they are identical

Are you saying that I should check if the 2 paths have common edges (segments of road)? This won’t be enough to determine if the 2 paths intersect, as there might be paths without common edges that still intersect.

edges or nodes, both are accessible via the Path object

I tried the method you suggested and I get the following lists of nodes for 2 paths that have different starting and ending points, but intersect somewhere in the middle:

[141196, 4391, 4390, 4389, 4388, 4387, 4386, 11911, 9793, 11677, 7167, 7022, 7023, 124506, 6475, 115519, 7024, 7025, 115524, 8534, 9723, 141197]

[141197, 9795, 6478, 8832, 9794, 9793, 5333, 9792, 9791, 9790, 141196]

It seems to me that the starting and ending nodes are somehow special, as the starting node of the first path is the same as the end node of the 2nd and the ending node of the fist path is the same as the starting node of the 2nd. Why are they like that, despite the fact that the 2 paths have different starting / ending points?

Every node in the graph is a junction in real world or an end standing node. Those nodes that you mean are so called virtual nodes (and edges) that we have to introduce per request in order to route just through a ‘partial’ edge. See https://github.com/graphhopper/graphhopper/blob/master/docs/core/low-level-api.md

Thanks! It all makes sense now.

1 Like