A common problem associated with bringing GIS data into pgRouting is the fact that the data is often not “noded” correctly. This will create invalid topologies, which will result in routes that are incorrect.

What we mean by “noded” is that at every intersection in the road network all the edges will be broken into separate road segments. There are cases like an over-pass and under-pass intersection where you can not traverse from the over-pass to the under-pass, but this function does not have the ability to detect and accommodate those situations.

This function reads the edge_table table, that has a primary key column id and geometry column named the_geom and intersect all the segments in it against all the other segments and then creates a table edge_table_noded. It uses the tolerance for deciding that multiple nodes within the tolerance are considered the same node.

Parameters

edge_table:

text Network table name. (may contain the schema name as well)

tolerance:

float8 tolerance for coincident points (in projection unit)dd

id:

text Primary key column name of the network table. Default value is id.

the_geom:

text Geometry column name of the network table. Default value is the_geom.

SELECTpgr_createTopology('edge_table',0.001);NOTICE:PROCESSING:NOTICE:pgr_createTopology('edge_table',0.001,'the_geom','id','source','target','true')NOTICE:Performingchecks,pelasewait.....NOTICE:CreatingTopology,Pleasewait...NOTICE:-------------> TOPOLOGY CREATED FOR 18 edgesNOTICE:RowswithNULLgeometryorNULLid:0NOTICE:Verticestablefortablepublic.edge_tableis:public.edge_table_vertices_pgrNOTICE:----------------------------------------------pgr_createtopology--------------------OK(1row)

SELECTpgr_createTopology('edge_table_noded',0.001);NOTICE:PROCESSING:NOTICE:pgr_createTopology('edge_table_noded',0.001,'the_geom','id','source','target','true')NOTICE:Performingchecks,pelasewait.....NOTICE:CreatingTopology,Pleasewait...NOTICE:-------------> TOPOLOGY CREATED FOR 21 edgesNOTICE:RowswithNULLgeometryorNULLid:0NOTICE:Verticestablefortablepublic.edge_table_nodedis:public.edge_table_noded_vertices_pgrNOTICE:----------------------------------------------pgr_createtopology--------------------OK(1row)

SELECTpgr_createTopology('edge_table',0.001);NOTICE:PROCESSING:NOTICE:pgr_createTopology('edge_table',0.001,'the_geom','id','source','target','true')NOTICE:Performingchecks,pelasewait.....NOTICE:CreatingTopology,Pleasewait...NOTICE:-------------> TOPOLOGY CREATED FOR 24 edgesNOTICE:RowswithNULLgeometryorNULLid:0NOTICE:Verticestablefortablepublic.edge_tableis:public.edge_table_vertices_pgrNOTICE:----------------------------------------------pgr_createtopology--------------------OK(1row)

To get the same analysis results as the topology of edge_table_noded, we do the following query:

SELECTpgr_analyzegraph('edge_table',0.001,rows_where:='id not in (select old_id from edge_table where old_id is not null)');NOTICE:PROCESSING:NOTICE:pgr_analyzeGraph('edge_table',0.001,'the_geom','id','source','target','id not in (select old_id from edge_table where old_id is not null)')NOTICE:Performingchecks,pelasewait...NOTICE:Analyzingfordeadends.Pleasewait...NOTICE:Analyzingforgaps.Pleasewait...NOTICE:Analyzingforisolatededges.Pleasewait...NOTICE:Analyzingforringgeometries.Pleasewait...NOTICE:Analyzingforintersections.Pleasewait...NOTICE:ANALYSISRESULTSFORSELECTEDEDGES:NOTICE:Isolatedsegments:0NOTICE:Deadends:6NOTICE:Potentialgapsfoundneardeadends:0NOTICE:Intersectionsdetected:0NOTICE:Ringgeometries:0pgr_createtopology--------------------OK(1row)

To get the same analysis results as the original edge_table, we do the following query:

SELECTpgr_analyzegraph('edge_table',0.001,rows_where:='old_id is null')NOTICE:PROCESSING:NOTICE:pgr_analyzeGraph('edge_table',0.001,'the_geom','id','source','target','old_id is null')NOTICE:Performingchecks,pelasewait...NOTICE:Analyzingfordeadends.Pleasewait...NOTICE:Analyzingforgaps.Pleasewait...NOTICE:Analyzingforisolatededges.Pleasewait...NOTICE:Analyzingforringgeometries.Pleasewait...NOTICE:Analyzingforintersections.Pleasewait...NOTICE:ANALYSISRESULTSFORSELECTEDEDGES:NOTICE:Isolatedsegments:2NOTICE:Deadends:7NOTICE:Potentialgapsfoundneardeadends:1NOTICE:Intersectionsdetected:1NOTICE:Ringgeometries:0pgr_createtopology--------------------OK(1row)

Or we can analyze everything because, maybe edge 18 is an overpass, edge 14 is an under pass and there is also a street level juction, and the same happens with edges 17 and 13.