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

1. Construct the graph

agouge edited this page Feb 15, 2013 · 10 revisions

First we build the graph where the edges are roads and the nodes are intersections by executing the following instruction on the input table routes:

EXECUTE ST_Graph(routes, 0.01, false, 'routes');

Please see the Javadoc for ST_Graph for an explanation of the parameters.

The two resulting output tables will be named routes.nodes and routes.edges. By default, routes.edges conserves all the columns in routes while appending three columns:

  • id Edge id
  • start_node Id for each start node
  • end_node Id for each end node

On the other hand, routes.nodes contains two columns:

  • the_geom The POINT geometry of each intersection
  • id The node id.

Optional: Add edge weights

If the graph is to be weighted, we have to specify the edge weights in an additional column of routes.edges. Any nonnegative double value can be used.

For example, we could use the length of each edge as the edge weight as follows:

ALTER TABLE routes.edges ADD COLUMN weight double;
UPDATE routes.edges SET weight=ST_Length(the_geom);