Installation on Ubuntu 9.04 (with PostgreSQL 8.3) with TSP and Driving Distance (Extras) and OSM data

After had some troubles to install pgRouting on Ubuntu 8.10, it works again with Ubuntu 9.04.

1. Install required packages

sudo apt-get install build-essential subversion cmake bzip2
sudo apt-get install postgresql-8.3-postgis postgresql-server-dev-8.3

If you're not planning to install CGAL from Ubuntu multiverse, you can use default Boost library from the repository. This will be version 1.34 at the moment.

sudo apt-get install libboost-graph-dev

If you install CGAL later from Ubuntu multiverse it will upgrade to Boost 1.35.
This might cause troubles if you compiled pgRouting core already with Boost 1.34.

For Driving Distance algorithm (multiverse repository)

sudo apt-get install libcgal*

For TSP algorithm

wget http://downloads.sourceforge.net/gaul/gaul-devel-0.1849-0.tar.gz?modtime=1114163427&big_mirror=0
tar -xzf gaul-devel-0.1849-0.tar.gz
cd gaul-devel-0.1849-0/
./configure --disable-slang
make
sudo make install
sudo ldconfig

2. Compile pgRouting core (with TSP and DD flag on)

svn checkout http://pgrouting.postlbs.org/svn/pgrouting/trunk pgrouting

cd pgrouting/
cmake -DWITH_TSP=ON -DWITH_DD=ON .
make
sudo make install

3. Setup PostgreSQL

Set local database connections to "trust" in "pg_hba.conf" to be able to work with PostgreSQL as user "postgres". Then restart PostgreSQL.

sudo gedit /etc/postgresql/8.3/main/pg_hba.conf 
sudo /etc/init.d/postgresql-8.3 restart

4. Create routing database

createdb -U postgres routing
createlang -U postgres plpgsql routing

Add PostGIS functions

psql -U postgres -f /usr/share/postgresql-8.3-postgis/lwpostgis.sql routing
psql -U postgres -f /usr/share/postgresql-8.3-postgis/spatial_ref_sys.sql routing

Add pgRouting functions

psql -U postgres -f /usr/share/postlbs/routing_core.sql routing
psql -U postgres -f /usr/share/postlbs/routing_core_wrappers.sql routing
psql -U postgres -f /usr/share/postlbs/routing_topology.sql routing

Add TSP functions

psql -U postgres -f /usr/share/postlbs/routing_tsp.sql routing
psql -U postgres -f /usr/share/postlbs/routing_tsp_wrappers.sql routing

Add Driving Distance functions

psql -U postgres -f /usr/share/postlbs/routing_dd.sql routing
psql -U postgres -f /usr/share/postlbs/routing_dd_wrappers.sql routing

5. Add road network data

Download archived version of OSM data from  CloudMade website. It comes as bzip2 archive named <country_name>.osm.bz2. For example, for Japan it would be

cd ..
wget http://downloads.cloudmade.com/asia/japan/japan.osm.bz2
bunzip2 japan.osm.bz2

Install osm2pgrouting

svn checkout http://pgrouting.postlbs.org/svn/pgrouting/tools/osm2pgrouting/trunk osm2pgrouting
cd osm2pgrouting
make

Eventually boost library is missing. Then run:

sudo apt-get update
sudo apt-get install libboost-graph-dev

Run conversion script

./osm2pgrouting -file ../japan.osm \
				-conf mapconfig.xml \
				-dbname routing \
				-user postgres \
				-clean \
				-host localhost

Connect to your database and make sure the tables have been created

psql -U postgres routing
\d
                 List of relations
 Schema |        Name         |   Type   |  Owner   
--------+---------------------+----------+----------
 public | classes             | table    | postgres
 public | geometry_columns    | table    | postgres
 public | nodes               | table    | postgres
 public | spatial_ref_sys     | table    | postgres
 public | types               | table    | postgres
 public | vertices_tmp        | table    | postgres
 public | vertices_tmp_id_seq | sequence | postgres
 public | ways                | table    | postgres
(8 rows)