pgRouting is an extension of PostGIS and adds routing functionality to PostGIS/PostgreSQL.
This Quick Start describes how to open a database with the command line and run a basic shortest path query with the sample test data.
psql -U user pgrouting
List of relations
Schema | Name | Type | Owner
--------+---------------------+----------+----------
public | geography_columns | view | postgres
public | geometry_columns | table | postgres
public | spatial_ref_sys | table | postgres
public | vertices_tmp | table | postgres
public | vertices_tmp_id_seq | sequence | postgres
public | ways | table | postgres
(6 rows)
SELECT * FROM shortest_path('
SELECT gid as id,
source::integer,
target::integer,
length::double precision as cost
FROM ways',
605, 359, false, false);
vertex_id | edge_id | cost
-----------+---------+---------------------
605 | 5575 | 0.0717467247513547
1679 | 2095 | 0.148344716070272
588 | 2094 | 0.0611856933258344
... | ... | ...
359 | -1 | 0
(82 rows)
SELECT gid, AsText(the_geom) AS the_geom
FROM dijkstra_sp('ways', 605, 359);
gid | the_geom
--------+---------------------------------------------------------------
168 | MULTILINESTRING((2.1633077 41.3802886,2.1637094 41.3803008))
169 | MULTILINESTRING((2.1637094 41.3803008,2.1638796 41.3803093))
170 | MULTILINESTRING((2.1638796 41.3803093,2.1640527 41.3803265))
... | ...
5575 | MULTILINESTRING((2.1436976 41.3897581,2.143876 41.3903893))
(81 rows)
Note
To update to the latest version of the tutorial, open a terminal window, then run sudo apt-get update && apt-get upgrade pgrouting-workshop