pgr_labelGraph
— Locates and labels sub-networks within a network which are not topologically connected.
Warning
These are proposed functions
Must be run after pgr_createTopology()
. No use of geometry
column. Only id
, source
and target
columns are required.
The function returns:
OK
when a column with provided name has been generated and populated successfully. All connected edges will have unique similar integer values. In case ofrows_where
condition, non participating rows will have -1 integer values.FAIL
when the processing cannot be finished due to some error. Notice will be thrown accordingly.rows_where condition generated 0 rows
when passed SQL condition has not been fulfilled by any row.
varchar pgr_labelGraph(text, text, text, text, text, text)
A network behind any routing query may consist of sub-networks completely isolated from each other. Possible reasons could be:
pgr_labelGraph() will create an integer column (with the name provided by the user) and will assign same integer values to all those edges in the network which are connected topologically. Thus better analysis regarding network structure is possible. In case of rows_where
condition, non participating rows will have -1 integer values.
Prerequisites:
Must run pgr_createTopology()
in order to generate source
and target
columns. Primary key column id
should also be there in the network table.
Function accepts the following parameters:
edge_table: | text Network table name, with optional schema name. |
---|---|
id: | text Primary key column name of the network table. Default is id . |
source: | text Source column name generated after pgr_createTopology() . Default is source . |
target: | text Target column name generated after pgr_createTopology() . Default is target . |
subgraph: | text Column name which will hold the integer labels for each sub-graph. Default is subgraph . |
rows_where: | text The SQL where condition. Default is true , means the processing will be done on the whole table. |
The sample data, has 3 subgraphs.
SET client_min_messages TO WARNING;
SET
SELECT pgr_labelGraph('edge_table', 'id', 'source', 'target', 'subgraph');
pgr_labelgraph
----------------
OK
(1 row)
SELECT subgraph, count(*) FROM edge_table group by subgraph;
subgraph | count
----------+-------
1 | 16
3 | 1
2 | 1
(3 rows)