Route through the same node twice


I’m calculating a route in London for car in CH:

From: 51.475366799530335,-0.08266079713853412
To: 51.54852593212133,-0.10544602854045428

I am printing the nodes through which the route passes and I notice that one node is repeated:

NODE → Time
124607 → 553948.0
97887 → 103554.0
9610 → 213335.0
8675 → 62984.0
57157 → 25337.0
57194 → 13010.0
56360 → 4518.0
NODE → Time
124607 → 181436.0
167082 → 65021.0
2081 → 19092.0
2081 → 36547.0
67941 → 8056.0

Is that possible? I think the shorted path cannot go through the same node twice.

I check the code and is accepting self loops

 public boolean accept(RoutingCHEdgeIteratorState edgeState) {
            int base = edgeState.getBaseNode();
            int adj = edgeState.getAdjNode();
            // always accept virtual edges, see #288
            if (base >= maxNodes || adj >= maxNodes)
                return true;

            // minor performance improvement: shortcuts in wrong direction are disconnected, so no need to exclude them
            if (edgeState.isShortcut())
                return true;

            return graph.getLevel(base) <= graph.getLevel(adj);

Why not exist the condition: if(base == adj) return false; ?


This is probably a loop shortcut. Take a route like this for example:

At the junction the red arrow is pointing to it does a right turn, because turning left is forbidden there. It then does a ‘p-turn’ to arrive at the same junction again and go straight to arrive at the destination. CH will represent this entire entire turn (going from the junction at the red arrow back to the same junction) as by a single shortcut edge, which is a loop in the CH graph (because it goes from one node to the same node).

Here is a similar screenshot for your route:


I’m guessing node 2081 is the one the arrow is pointing to. You can check this by enabling the MVT layer in the layers menu and hovering the adjacent edges.

Yes, it’s a shortcut. Then in CH is that possible due to the shortcuts.

Many thanks @easbar

How I can enable the MVT layer?

It only works when you run the GraphHopper server yourself. But I’m assuming you do? Make sure it is enabled in your config.yml: There needs to be a line: web.mvt.enabled: true

Make sure it is enabled in your config.yml: There needs to be a line: web.mvt.enabled: true

Hm, no actually I’m not sure this is needed (it looks like it is not).

The only way to disable it seems to be setting with_tiles to false in options.js, but you probably did not do this so I’m surprised the mvt option is missing in your layers menu.

I’m not running the UI locally. I will try to run. Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.