Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

3. Do graph analysis

agouge edited this page Feb 18, 2013 · 31 revisions

A. Execute ST_GraphAnalysis

Weighted

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

Unweighted

We could just as easily consider the graph to be unweighted bidirectional:

EXECUTE ST_GraphAnalysis(routes_1.edges, 1, 'routes_1_unweighted', 3);

B. Recover the node geometries

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;

C. Clean up

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).

RESULT

We obtain the table routes_1.graph_analysis containing the betweenness and closeness indices for each node in connected component 1.

Further calculations

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