Bienvenue sur PostGIS.fr

Bienvenue sur PostGIS.fr , le site de la communauté des utilisateurs francophones de PostGIS.

PostGIS ajoute le support d'objets géographique à la base de données PostgreSQL. En effet, PostGIS "spatialise" le serverur PostgreSQL, ce qui permet de l'utiliser comme une base de données SIG.

Maintenu à jour, en fonction de nos disponibilités et des diverses sorties des outils que nous testons, nous vous proposons l'ensemble de nos travaux publiés en langue française.

source: trunk/workshop-routing-foss4g/chapters/php_server.rst @ 63

Revision 63, 2.5 KB checked in by djay, 7 years ago (diff)

Initial import of pgROuting workshop for translation. Section 1 to 3 translated, pleae review.

RevLine 
[63]1==============================================================================================================
2Server side script with PHP
3==============================================================================================================
4
5We will use a PHP script to make the routing query and send the result back to the web client.
6
7The following steps are necessary:
8
9* Retrieve the start and end point coordinates.
10* Find the closest edge to start/end point.
11* Take either the start or end vertex of this edge (for Dijkstra/ A-Star) or the complete edge (Shooting-Star) as start of the route and end respectively.
12* Make the Shortest Path database query.
13* Transform the query result to XML or better GeoJSON and send it back to the web client.
14
15.. note::
16       
17        To keep this example as simple as possible with focus on routing queries, this PHP script doesn't validate request parameters nore does it deal with PHP security issues.
18
19Let's start with some PHP template and then place this file in a directory, which is accessible by Apache:
20
21.. literalinclude:: ../../web/php/pgrouting.php
22        :language: php
23        :lines: 1-18
24
25         
26-------------------------------------------------------------------------------------------------------------
27Closest edge
28-------------------------------------------------------------------------------------------------------------
29
30Usually the start and end point, which we retrieved from the client, is not the start or end vertex of an edge. It is more convenient to look for the closest edge than for the closest vertex, because Shooting Star algorithm is “edge-based”. For “vertex-based” algorithms (Dijkstra, A-Star) we can choose arbitrary start or end of the selected edge.
31
32.. literalinclude:: ../../web/php/pgrouting.php
33        :language: php
34        :lines: 20-56
35         
36         
37-------------------------------------------------------------------------------------------------------------
38Routing query
39-------------------------------------------------------------------------------------------------------------
40
41.. literalinclude:: ../../web/php/pgrouting.php
42        :language: php
43        :lines: 58-116
44
45
46-------------------------------------------------------------------------------------------------------------
47GeoJSON output
48-------------------------------------------------------------------------------------------------------------
49
50OpenLayers allows to draw lines directly using GeoJSON format, so our script returns a GeoJSON FeatureCollection object:
51
52.. literalinclude:: ../../web/php/pgrouting.php
53        :language: php
54        :lines: 118-
55
Note: See TracBrowser for help on using the repository browser.