3

I wondered if there's an easy way to 'clean up' a pgRouting network by removing those edges that do not connect with the global network. Otherwise you risk to end up with cost values of -1, meaning there exists no path between the given source and target (pgr_kdijkstra).

enter image description here

I handled the osm.pbf file with osm2po (v4.8.8) and imported the network into a spatial database with the generated SQL script.


Getting back to my question, I found it lacked a bit of context :-) So...

I had generated a set of points as the centroids of a polygon layer. Eventually I want to use these centroids as start/end nodes to calculate shortest paths. As these points do not belong to a network, I cannot use them directly for routing. Therefore I searched for the nodes that are closest to the set of centroids by means of Vector > Analysis Tools > Distance matrix in QGIS. The problem, however, is that it is possible these 'corresponding' nodes are unreachable from the global network. When calculating shortest paths, they are indicated with a cost of -1.

As @Carsten noted, commenting out the following line in the config file of osm2po

postp.1.class = de.cm.osm2po.plugins.PgVertexWriter

will detect all dead ends or 'dangles'. As such you are able to filter them out from the whole set of nodes. But then, the problem indeed is that if an isolated mini-network consists of more than 1 segment, the vertices in the middle are not filtered out as these vertices are no dead ends. The figure from above represents the 'ideal' situation of an isolated mini-network of 1 segment and thus 2 dead ends. Eliminating those nodes results in eliminating the whole mini-network, which is nice.

So in fact, my question should have been 'How to eliminate (or detect) nodes and segments that are not connected to the global network'? That requires a little more (post)processing, as it is not incorporated as a preprocessing step which @Carsten also mentions in a related question.

5

In PgRouting 2.0 there is a pgr_analyzeGraph function that will identify isolated segments. Isolated segments will have a dead-end at each end so a query like this against your network and vertices tables:

SELECT *
    FROM mytab a, mytab_vertices_pgr b, mytab_vertices_pgr c
    WHERE a.source=b.id AND b.cnt=1 AND a.target=c.id AND c.cnt=1;

will identify the segments you want.

See http://docs.pgrouting.org/2.0/en/doc/src/tutorial/analytics.html for more information.

2

Since you mentioned using QGIS, I had a similar problem, so I developed a QGIS plugin which is now available in the official QGIS plugins repository and can be found in the QGIS menu: Plugins / Manage and Install Plugins... and search for Disconnected Islands.

http://plugins.qgis.org/plugins/disconnected-islands/

This plugin runs on a polyline layer, building up a road (or rail, etc.) network graph of connected links. It then analyses connected subgraphs, ones that are connected to each other, but not connected to isolated or floating links. It creates an additional attribute containing the group ID of the subgraph. This can then be used to style the layer with Categorised styles, or Zoom to selection. The disconnected links (everything with a group ID <> 0) can then be fixed or removed.

Source code can be forked from: https://github.com/AfriGIS-South-Africa/disconnected-islands

1

Hmmm... no answers here ... Ok... look for this line inside the config and comment it out:

postp.1.class = de.cm.osm2po.plugins.PgVertexWriter

This will give you an additional table of vertices. Look for the ref_count-column. A value of "0" indicates dead ends or "no crossing". But what are you going to interpret in your example above if it's composed of two or more sections?

  • Thanks @Carsten for your answer. I'll have a look at it as soon as possible and see whether using PgVertexWriter is a solution for me or not. Concerning your remark: do you mean, 'what are you going to do if you have multiple street segments (so something like an 'isolated mini network') that are not connected to the global network?'? – kadéem Aug 20 '14 at 8:16
0

I've ran into a similar problem with a large network (~400k edges). Peter's plugin works, but took many hours and all my RAM, probably because it partitions edges using their geometries when all I cared about was their topology.

So I've made my own script in python, that directly removes all minor groups, considering as "minor" the ones that have less than 10% of the edges in the network. It solved my problem in less than 10 seconds.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.