pgr_analyzeOneWay  pgRouting Manual (3.3)
pgr_analyzeOneWay
pgr_analyzeOneWay
 Analyzes oneway Sstreets and identifies flipped segments.
This function analyzes oneway streets in a graph and identifies any flipped segments.
Availability

Version 2.0.0

Official function

Description
The analyses of one way segments is pretty simple but can be a powerful tools to identifying some the potential problems created by setting the direction of a segment the wrong way. A node is a source if it has edges the exit from that node and no edges enter that node. Conversely, a node is a sink if all edges enter the node but none exit that node. For a source type node it is logically impossible to exist because no vehicle can exit the node if no vehicle and enter the node. Likewise, if you had a sink node you would have an infinite number of vehicle piling up on this node because you can enter it but not leave it.
So why do we care if the are not feasible? Well if the direction of an edge was reversed by mistake we could generate exactly these conditions. Think about a divided highway and on the north bound lane one segment got entered wrong or maybe a sequence of multiple segments got entered wrong or maybe this happened on a roundabout. The result would be potentially a source and/or a sink node.
So by counting the number of edges entering and exiting each node we can identify both source and sink nodes so that you can look at those areas of your network to make repairs and/or report the problem back to your data vendor.
Prerequisites
The edge table to be analyzed must contain a source column and a target column filled with id’s of the vertices of the segments and the corresponding vertices table

Use pgr_createVerticesTable to create the vertices table.

Use pgr_createTopology to create the topology and the vertices table.
Signatures
text pgr_analyzeOneWay(geom_table text,
text[] s_in_rules, text[] s_out_rules,
text[] t_in_rules, text[] t_out_rules,
text oneway='oneway', text source='source', text target='target',
boolean two_way_if_null=true);
Parameters
 edge_table :

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

text[]
source node in rules  s_out_rules :

text[]
source node out rules  t_in_rules :

text[]
target node in rules  t_out_rules :

text[]
target node out rules  oneway :

text
oneway column name name of the network table. Default value isoneway
.  source :

text
Source column name of the network table. Default value issource
.  target :

text
Target column name of the network table. Default value istarget
.  two_way_if_null :

boolean
flag to treat oneway NULL values as bidirectional. Default value istrue
.
Note
It is strongly recommended to use the named notation. See pgr_createVerticesTable or pgr_createTopology for examples.
The function returns:

OK
after the analysis has finished.
Uses the vertices table:
_vertices_pgr. 
Fills completely the
ein
andeout
columns of the vertices table.


FAIL
when the analysis was not completed due to an error.
The vertices table is not found.

A required column of the Network table is not found or is not of the appropriate type.

The names of source , target or oneway are the same.

The rules are defined as an array of text strings that if match the
oneway
value would be counted as
true
for the source or target
in
or
out
condition.
The Vertices Table
The vertices table can be created with pgr_createVerticesTable or pgr_createTopology
The structure of the vertices table is:
 id :

bigint
Identifier of the vertex.  cnt :

integer
Number of vertices in the edge_table that reference this vertex. See pgr_analyzeGgraph .  chk :

integer
Indicator that the vertex might have a problem. See pgr_analyzeGraph .  ein :

integer
Number of vertices in the edge_table that reference this vertex as incoming.  eout :

integer
Number of vertices in the edge_table that reference this vertex as outgoing.  the_geom :

geometry
Point geometry of the vertex.
Additional Examples
SELECT pgr_analyzeOneWay('edge_table',
ARRAY['', 'B', 'TF'],
ARRAY['', 'B', 'FT'],
ARRAY['', 'B', 'FT'],
ARRAY['', 'B', 'TF'],
oneway:='dir');
NOTICE: PROCESSING:
NOTICE: pgr_analyzeOneway('edge_table','{"",B,TF}','{"",B,FT}','{"",B,FT}','{"",B,TF}','dir','source','target',t)
NOTICE: Analyzing graph for one way street errors.
NOTICE: Analysis 25% complete ...
NOTICE: Analysis 50% complete ...
NOTICE: Analysis 75% complete ...
NOTICE: Analysis 100% complete ...
NOTICE: Found 0 potential problems in directionality
pgr_analyzeoneway

OK
(1 row)
The queries use the Sample Data network.
See Also

Topology  Family of Functions for an overview of a topology for routing algorithms.

Graph Analytics for an overview of the analysis of a graph.

pgr_analyzeGraph to analyze the edges and vertices of the edge table.

pgr_createVerticesTable to reconstruct the vertices table based on the source and target information.
Indices and tables