-
Notifications
You must be signed in to change notification settings - Fork 4
3. Do graph analysis
We do the actual graph analysis on connected component 1 as follows:
EXECUTE ST_GraphAnalysis(routes_1.edges, 'weight', 'routes_1', 3);
Please see the Javadoc for ST_GraphAnalysis
(pending) for an explanation of the parameters. The default output table prefix is output
.
This produces a table routes.graph_analysis
containing
-
id
The node id -
betweenness_centrality
Betweenness centrality -
closeness_centrality
Closeness centrality
We could just as easily consider the graph to be unweighted bidirectional:
EXECUTE ST_GraphAnalysis(routes_1.edges, 1, 'routes_1_unweighted', 3);
It remains only to match the node ids with their geometries in routes.nodes
(or in routes_1.nodes
).
CREATE TABLE routes_1.graph_analysis AS SELECT a.the_geom, b.* FROM routes.nodes a, routes_1.graph_analysis b WHERE a.id=b.id;
For unweighted graphs:
CREATE TABLE routes_1_unweighted.graph_analysis AS SELECT a.the_geom, b.* FROM routes.nodes a, routes_1_unweighted.graph_analysis b WHERE a.id=b.id;
Here we get rid of intermediate tables we no longer need:
DROP TABLE routes_1.nodes PURGE;
DROP TABLE routes_1_start.edges PURGE;
DROP TABLE routes_1_end.edges PURGE;
DROP TABLE routes_1.edges PURGE;
DROP TABLE routes_1_tmp.graph_analysis PURGE;
The PURGE
keyword indicates that the tables should also be deleted from disk (and not left stored in the workspace).
We obtain the table routes_1.graph_analysis
containing the betweenness and closeness indices for each node in connected component 1.
At the end of this script, we are left with the following tables, which may be reused starting from Step 2.C to do graph analysis on another connected component:
connected_components
connected_component_totals
routes.nodes
routes.edges