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.

Server side script with PHP

We will use a PHP script to make the routing query and send the result back to the web client.

The following steps are necessary:

  • Retrieve the start and end point coordinates.
  • Find the closest edge to start/end point.
  • 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.
  • Make the Shortest Path database query.
  • Transform the query result to XML or better GeoJSON and send it back to the web client.

Note

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.

Let's start with some PHP template and then place this file in a directory, which is accessible by Apache:

System Message: ERROR/3 (<string>, line 21)

Unknown directive type "literalinclude".

.. literalinclude:: ../../web/php/pgrouting.php
        :language: php
        :lines: 1-18

Closest edge

Usually 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.

System Message: ERROR/3 (<string>, line 32)

Unknown directive type "literalinclude".

.. literalinclude:: ../../web/php/pgrouting.php
        :language: php
        :lines: 20-56

Routing query

System Message: ERROR/3 (<string>, line 41)

Unknown directive type "literalinclude".

.. literalinclude:: ../../web/php/pgrouting.php
        :language: php
        :lines: 58-116

GeoJSON output

OpenLayers allows to draw lines directly using GeoJSON format, so our script returns a GeoJSON FeatureCollection object:

System Message: ERROR/3 (<string>, line 52)

Unknown directive type "literalinclude".

.. literalinclude:: ../../web/php/pgrouting.php
        :language: php
        :lines: 118-
Note: See TracBrowser for help on using the repository browser.