Est fournit ici un résumé des commandes nécessaires pour la compialtion de PgRouting 1.02 sous Ubuntu Studio
ATTENTION: il faut se baser sur le guide disponible à Â
http://pgrouting.postlbs.org/wiki/1.x/InstallationManual mais celui -ci n'est pas suffisament complet pour une installation complète notamment au niveau des options possibles pour 'cmake' de PgRouting.
0. Pré-requis
Comme à  l'accoutumée
mkdir /mnt/sources
cd /mnt/sources/
wget http://prdownloads.sourceforge.net/gaul/gaul-devel-0.1849-0.tar.gz?download
tar xvzf gaul-devel-0.1849-0.tar.gz
cd gaul-devel-0.1849-0
./configure --enable-slang=no
make
make install
cd ..
apt-get install libboost-graph-dev libboost-graph1.33.1 libboost-dev
wget ftp://ftp.mpi-sb.mpg.de/pub/outgoing/CGAL/CGAL-3.3.tar.gz
tar xvzf CGAL-3.3.tar.gz
cd CGAL-3.3
./install_cgal --prefix=/usr/local/cgal --with-boost=n --without-autofind -ni /usr/bin/g++
1. Compilation
export CGAL_MAKEFILE="/usr/share/cgal/cgal.mk"
cmake -DWITH_TSP=ON -DWITH_DD=ON -DPOSTGRESQL_INCLUDE_DIR=$(pg_config --includedir-server)
qui va recracher
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Check size of void*
-- Check size of void* - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Found PostgreSQL: /usr/local/pgsql/include/server, /usr/lib/libpq.so
Boost headers were found here: /usr/include
Output directory for libraries is set to /usr/local/pgsql/lib
-- Found PGROUTING_CORE core: /mnt/sources/pgrouting/core/src
Installation directory for libraries is set to /usr/local/pgsql/lib and for SQL files is set to /usr/share/postlbs
-- Found GAUL: /usr/local/lib/libgaul.so, /usr/local/lib/libgaul_util.so
Installation directory for libraries is set to /usr/local/pgsql/lib
-- Found CGAL: /usr/include, /usr/lib/libCGAL.so
-- Configuring done
-- Generating done
-- Build files have been written to: /mnt/sources/pgrouting
root@olivia:/mnt/sources/pgrouting# make
Scanning dependencies of target routing_tsp
[ 8%] Building C object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp.o
[ 16%] Building CXX object extra/tsp/src/CMakeFiles/routing_tsp.dir/tsp_solver.o
Linking CXX shared library ../../../lib/librouting_tsp.so
[ 16%] Built target routing_tsp
Scanning dependencies of target routing_dd
[ 25%] Building C object extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha.o
[ 33%] Building CXX object extra/driving_distance/src/CMakeFiles/routing_dd.dir/alpha_drivedist.o
[ 41%] Building CXX object extra/driving_distance/src/CMakeFiles/routing_dd.dir/boost_drivedist.o
[ 50%] Building C object extra/driving_distance/src/CMakeFiles/routing_dd.dir/drivedist.o
Linking CXX shared library ../../../lib/librouting_dd.so
[ 50%] Built target routing_dd
Scanning dependencies of target routing
[ 58%] Building C object core/src/CMakeFiles/routing.dir/dijkstra.o
[ 66%] Building C object core/src/CMakeFiles/routing.dir/astar.o
[ 75%] Building C object core/src/CMakeFiles/routing.dir/shooting_star.o
[ 83%] Building CXX object core/src/CMakeFiles/routing.dir/boost_wrapper.o
[ 91%] Building CXX object core/src/CMakeFiles/routing.dir/astar_boost_wrapper.o
[100%] Building CXX object core/src/CMakeFiles/routing.dir/shooting_star_boost_wrapper.o
Linking CXX shared library ../../lib/librouting.so
[100%] Built target routing
2. Installation
Un simple make install résultera en
root@olivia:/mnt/sources/pgrouting# make install
[ 16%] Built target routing_tsp
[ 50%] Built target routing_dd
[100%] Built target routing
Linking CXX shared library CMakeFiles/CMakeRelink.dir/librouting_tsp.so
Linking CXX shared library CMakeFiles/CMakeRelink.dir/librouting_dd.so
Linking CXX shared library CMakeFiles/CMakeRelink.dir/librouting.so
Install the project...
-- Install configuration: ""
-- Install configuration: ""
-- Install configuration: ""
-- Install configuration: ""
-- Installing /usr/local/pgsql/lib/librouting.so
-- Install configuration: ""
-- Installing /usr/share/postlbs/routing_core.sql
-- Installing /usr/share/postlbs/routing_core_wrappers.sql
-- Install configuration: ""
-- Install configuration: ""
-- Installing /usr/local/pgsql/lib/librouting_tsp.so
-- Install configuration: ""
-- Installing /usr/share/postlbs/routing_tsp.sql
-- Installing /usr/share/postlbs/routing_tsp_wrappers.sql
-- Install configuration: ""
-- Install configuration: ""
-- Installing /usr/local/pgsql/lib/librouting_dd.so
-- Install configuration: ""
-- Installing /usr/share/postlbs/routing_dd.sql
-- Installing /usr/share/postlbs/routing_dd_wrappers.sql
3. Création d'une base chargée des fonctionnalités de PostGIS et de PgRouting
createdb -U postgres -E UNICODE routing
createlang -U postgres plpgsql routing
psql -U postgres -f /path/to/postgis/lwpostgis.sql routing
psql -U postgres -f /usr/local/pgsql/share/lwpostgis.sql routing
psql -U postgres -f /usr/local/pgsql/share/spatial_ref_sys.sql routing
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_tsp.sql routing
psql -U postgres -f /usr/share/postlbs/routing_tsp_wrappers.sql routing
psql -U postgres -f /usr/share/postlbs/routing_dd.sql routing
psql -U postgres -f /usr/share/postlbs/routing_dd_wrappers.sql routing
4. Test sur un jeu de données
dropdb routing;
createdb -U postgres -E UNICODE routing;
createlang -U postgres plpgsql routing;
psql -U postgres -f /usr/local/pgsql/share/lwpostgis.sql routing;
psql -U postgres -f /usr/local/pgsql/share/spatial_ref_sys.sql routing;
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_tsp.sql routing;
psql -U postgres -f /usr/share/postlbs/routing_tsp_wrappers.sql routing;
psql -U postgres -f /usr/share/postlbs/routing_dd.sql routing;
psql -U postgres -f /usr/share/postlbs/routing_dd_wrappers.sql routing;
#
# Test sur un jeu de données
#
mkdir tmp
cd tmp
wget http://www.davidgis.fr/download/troncon_route.zip;
unzip troncon_route.zip;
shp2pgsql -DI troncon_route.shp reseau|psql routing;
#
# modications nécessaires sur la table et test
#
echo "BEGIN TRANSACTION;
ALTER TABLE reseau ADD COLUMN source integer;
ALTER TABLE reseau ADD COLUMN target integer;
ALTER TABLE reseau ADD COLUMN x1 double precision;
ALTER TABLE reseau ADD COLUMN y1 double precision;
ALTER TABLE reseau ADD COLUMN x2 double precision;
ALTER TABLE reseau ADD COLUMN y2 double precision;
ALTER TABLE reseau ADD COLUMN length double precision;
ALTER TABLE reseau ADD COLUMN cost double precision;
ALTER TABLE reseau ADD COLUMN reverse_cost double precision;
SELECT assign_vertex_id('reseau', 0000001, 'the_geom', 'gid');
UPDATE reseau SET (length,cost,reverse_cost) = (length(the_geom),length(the_geom),length(the_geom)),x1 = x(PointN(the_geom, 1)),y1 = y(PointN(the_geom, 1)),x2 = x(PointN(the_geom, NumPoints(the_geom))),y2 = y(PointN(the_geom, NumPoints(the_geom)));
UPDATE reseau SET reverse_cost = -1 WHERE sens = 'sens direct';
END TRANSACTION;
drop table if exists aller,retour;
begin;
create table aller(gid int4) with oids;
SELECT AddGeometryColumn( 'aller', 'the_geom', -1, 'MULTILINESTRING', 2 );
insert into aller(the_geom) select the_geom from astar_sp_directed('reseau',1,51,false,true);
create table retour(gid int4) with oids;
SELECT AddGeometryColumn( 'retour', 'the_geom', -1, '
MULTILINESTRING', 2 );
insert into retour(the_geom) select the_geom from astar_sp_directed('reseau',51,1,false,true);
end;
"|psql routing
Ici j'ai importé un shapefile dans la table réseau. Suite à  l'import, une table réseau est crée et mis à  jour avec les champs requis par pgrouting.
Un échantillon de la table sera
routing=# select gid,sens,source,target,astext(the_geom),x1,y1,x2,y2,cost,reverse_cost from reseau limit 10;
gid | sens | source | target | astext | x1 | y1 | x2 | y2 | cost | reverse_cost
-----+-------------+--------+--------+----------------------------------+----+-----+----+-----+------+--------------
1 | double sens | 1 | 2 | MULTILINESTRING((1 0,5 0)) | 1 | 0 | 5 | 0 | 4 | 4
2 | double sens | 2 | 3 | MULTILINESTRING((5 0,5 6)) | 5 | 0 | 5 | 6 | 6 | 6
3 | double sens | 4 | 5 | MULTILINESTRING((0 7.5,3 7.5)) | 0 | 7.5 | 3 | 7.5 | 3 | 3
8 | double sens | 6 | 8 | MULTILINESTRING((7 7.5,11 7.5)) | 7 | 7.5 | 11 | 7.5 | 4 | 4
9 | double sens | 8 | 9 | MULTILINESTRING((11 7.5,11 11)) | 11 | 7.5 | 11 | 11 | 3.5 | 3.5
10 | double sens | 8 | 10 | MULTILINESTRING((11 7.5,14 7.5)) | 11 | 7.5 | 14 | 7.5 | 3 | 3
11 | double sens | 10 | 11 | MULTILINESTRING((14 7.5,21 7.5)) | 14 | 7.5 | 21 | 7.5 | 7 | 7
12 | double sens | 10 | 12 | MULTILINESTRING((14 7.5,14 11)) | 14 | 7.5 | 14 | 11 | 3.5 | 3.5
13 | double sens | 12 | 13 | MULTILINESTRING((14 11,18 11)) | 14 | 11 | 18 | 11 | 4 | 4
14 | double sens | 13 | 14 | MULTILINESTRING((18 11,18 13)) | 18 | 11 | 18 | 13 | 2 | 2
(10 lignes)