Suite à  mon précédent billet, je me suis amusé à  tester les données NavTeq de ADCI avec le module PgRoutin de KaMap. Un exemple de démo avec les données de Orkney est visible à  kappa.gonfi.org/dev/gonfi-ka-map/htdocs/index_routing.html
J'ai réussi à  obtenir par exemple la screenshot suivante pour mes propres données 
Une démo est disponible chez moi à  http://www.davidgis.fr/ka-map/index_routing.html
Pour commencer il faut suivre les indications de http://ka-map.ominiverdi.org/wiki/index.php/KaRouting. Malheureusement il s'avère que les indications fournies sont incomplètes
. Reprenons ici les détails de l'installation
On s'assure par exemple d'avoir le jeu de tests de PgRouting provenant de http://www.postlbs.org/postlbs-cms/en/download à  savoir «pgRouting Sample Application»
. Chez moi, j'ai décompressé le répertoire dans mon "/var/www/". J'ai ensuite copié tout ce qui était associé à  streets.shp
dans /var/www/routingj/data/
cp streets.* /var/www/routingj/data/
J'ai ensuite crée la mapfile suivante /var/www/routingj/maps/kamap-streets.map
dont le contenu est
MAP
IMAGETYPE PNG
EXTENT -77.1166763305664 38.7924194335938 -76.909538269043 38.9952430725098
#SIZE 500 489.585635359116
SIZE 200 195.834254143646
IMAGECOLOR 255 255 255
SHAPEPATH "../data"
FONTSET "../fonts/fonts.list"
REFERENCE
IMAGE "/var/www/keymap-streets.png"
EXTENT -77.1166763305664 38.7924194335938 -76.909538269043 38.9952430725098
STATUS ON
COLOR -1 -1 -1
OUTLINECOLOR 255 0 0
SIZE 200 164
END
WEB
IMAGEPATH "/var/www/tmp/"
IMAGEURL "/tmp/"
END
PROJECTION
"init=epsg:4326" # JGD2000
END
UNITS DD
SYMBOL
NAME "hatch"
TYPE hatch
END
LAYER
NAME "roads"
DATA streets
STATUS DEFAULT
TYPE LINE
CLASS
COLOR 155 155 155
END
END
END
Bien sà »r pour calculer l'extent et les dimensions adéquates de l'image pour width=500
, je me suis servi des requêtes suivantes
routing=# select extent(the_geom) from streets_edges;
extent
---------------------------------------------------------------------------
BOX(-77.1166763305664 38.7924194335938,-76.909538269043 38.9952430725098)
(1 ligne)
et de
routing=# SELECT
500*(abs(Ymax(foo.extent)-Ymin(foo.extent))/abs(Xmax(foo.extent)-Xmin(foo.extent)))
AS hauteur
FROM (SELECT Extent(the_geom) FROM streets_edges) AS foo;
hauteur
------------------
489.585635359116
(1 ligne)
Générer la keymap pour la légende
Pour connaà ®tre les dimensions pour
width=200
routing=# SELECT
200*(abs(Ymax(foo.extent)-Ymin(foo.extent))/abs(Xmax(foo.extent)-Xmin(foo.extent)))
AS hauteur
FROM (SELECT Extent(the_geom) FROM streets_edges) AS foo;
hauteur
------------------
195.834254143646
(1 ligne)
Le script php suivant a amplement suffit pour générer la keymap
/var/www/keymap-streets.png
<html>
<body>
<?php
$sw_MapFile = "/var/www/routingj/maps/kamap-streets.map";
$map = ms_newMapObj( $sw_MapFile );
$image = $map->draw();
//$image_url = $image->saveWebImage(MS_PNG,1,1,0);
$image->saveImage("/var/www/keymap-streets.png");
echo "<IMG
BORDER=0
SRC='".$image_url."'
width='".$map->width."' height='".$map->height."'/>
<BR>";
?>
</body>
</html>
Configuration de PgRouting avec Kamap
On peut télécharger la CVS disponible à  http://ka-map.ominiverdi.org/CVSimg/ka-map-cvs-image.tar.gz
cd /var/www/
wget http://ka-map.ominiverdi.org/CVSimg/ka-map-cvs-image.tar.gz
tar xvzf ka-map-cvs-image.tar.gz
Ce qui donnera le répertoire
ka-map
.
Comme précisé dans le wiki
i
cd ka-map
cp include/config.routing.dist.php include/config.php
Par rapport au contenu proposé voici le mien avec les différences notables en gras
// $aszGMap = array (
// 'title' => 'GMap 75',
// 'path' => '/var/www/gmap/htdocs/gmap75.map',
// 'scales' => array( 40000000, 25000000, 12000000, 7500000, 3000000, 1000000 ),
// 'format' =>'PNG'
// /* Sample authorized_users entry. See auth.php for more details:
// * ,'authorized_users' => array('popplace' => array('user1', 'user2'),
// * 'park' => array('user1')
// */
//);
$aszKaRoute = array (
'title' => 'Routing',
'path' => '/var/www/routingj/maps/kamap-streets.map',
'scales' => array(100000,50000,10000 ),
'format' =>'PNG'
/* Sample authorized_users entry. See auth.php for more details:
* ,'authorized_users' => array('popplace' => array('user1', 'user2'),
* 'park' => array('user1')
*/
);
$aszMapFiles = array( 'routeMap'=>$aszKaRoute);
/******************************************************************************
* figure out which map file to use and set up the necessary variables for
* the rest of the code to use. This does need to be done on every page load
* unfortunately.
*
* szMap should be set to the default map file to use but can change if
* this script is called with map=.
*/
$szMap = 'routeMap';
/******************************************************************************
* Configure kaRouting settings
* the array set the second mapfile you need to call and let kaRouting.php
* override and the postgres connection string
*/
$kaRoute = Array(
'routeMap' => '/var/www/routingj/maps/mapfile.map',//the second mapfile -should be changed with an SLD file
'pgConn' => 'dbname=routing host=localhost port=5432 user=postgres password=empr888',
'myGraphTable' => 'streets_edges',
'costColumn' => 'length',
'reverseCostColumn' => 'reverse_cost',
'directed' => 'false',//check pgRouting docs for this value
'has_reverse_cost' => 'true',//check pgRouting docs for this value
'buffer' => '0.01'//should be related to your map unit
);
La pour la suite, il faut créer la mapfile /var/www/routingj/maps/mapfile.map
dont le contenu sera - conformément au wiki -
MAP
IMAGETYPE png
EXTENT 139.602 35.413 139.678 35.489
SIZE 550 450
IMAGECOLOR 255 255 255
SHAPEPATH "data" #there are no shapes
FONTSET "../fonts/fonts.list"
WEB
IMAGEPATH "../tmp/"
IMAGEURL "/routingj/tmp/"
END
PROJECTION
"init=epsg:4612" # JGD2000. the kanagawa one
END
UNITS DD
SYMBOL
NAME "hatch"
TYPE hatch
END
LAYER
NAME "path"
CONNECTION "user=postgres password=empr888 dbname=routing host=localhost port=5432"
CONNECTIONTYPE postgis
STATUS OFF
TYPE LINE
CLASS
NAME "path"
STYLE
COLOR 155 0 0
WIDTH 2
END
END
END
END
Rappel: Création de la table streets_edges
Par la suite, on s'assurera pour la création de la table streets_egdes de suivre les indications de http://www.davidgis.fr/documentation/win32/html/apa.html aux sections «A.8.1. Importation d'un jeu de données NavTeq» et «A.8.2. Noeuds du réseau et direction pour le routage».
Recommencdations supplémentaires du wiki
Pour être conforme au wiki, il faut ensuite modifier son fichier de configuration d'Apache
Alias /ka-map/ "/var/www/ka-map/htdocs/"
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
Et ensuite de créer la table suivante dont le contenu sera
CREATE TABLE kroute (
gid serial NOT NULL,
sessionid text,
the_geom geometry NOT NULL,
date timestamp without time zone,
CONSTRAINT enforce_dims_the_geom CHECK ((ndims(the_geom) = 2)),
CONSTRAINT enforce_geotype_the_geom CHECK (((geometrytype(the_geom) = 'MULTILINESTRING'::text) OR (the_geom IS NULL))),
CONSTRAINT enforce_srid_the_geom CHECK ((srid(the_geom) = -1))
);
Pour lancer l'application, il suffira de pointer vers
http://localhost/ka-map/index_routing.html