[mapserver-users] optimal path between two points.

Stephen Woodbridge woodbri at swoodbridge.com
Mon Jan 19 15:37:53 EST 2009


Valeria Muñoz wrote:
> frank
>  
> thanks for the tips.  I use prRouting  and create the table 
> dijsktra_result. Now how can I implement with my mapfile? , how deliver 
> the data .. have some sample code?
> 
> thanks for your help.
> 
> 2009/1/19 Frank Warmerdam <warmerdam at pobox.com <mailto:warmerdam at pobox.com>>
> 
>     Valeria Muñoz wrote:
> 
>         Hi
>          I would like to implement the service "optimum path between 2
>         points," can someone help me to be able to implement it?. The
>         general idea is that a user picks a point A and point B and a
>         display on the map the best route to get from point A to B.
> 
> 
>     Valeria,
> 
>     MapServer itself does not do route calculation.  You might find some
>     useful pointers on this page:
> 
>      http://wiki.osgeo.org/wiki/OpenRouter
> 
>     I think the pgRouting (built on postgres/postgis) is the best bet for
>     integration with MapServer.

So you have various options depending on the client software you are 
using. So here are some ideas for you:

1) put the route into a results table with a unique id, and pass the 
unique id back to the client where it can then request the route image 
via a mapserver mapfile the connects to the postgis database and 
requests the layer be drawn with the unique id to select the appropriate 
route.

2) make an ajax request to generate the route and return the polyline as 
  an xml or json object back to the client. The client then parses the 
result document and displays the route over the map.

3) if you use OpenLayers for the client then you can use it to help you 
do 1) as an image, or 1) as a wfs layer, or 2) as a vector layer.

You can look at the source for my demo page 
http://imaptools.com/leaddog/routing/dd.html which does this with a 
modified version of pgRouting (pgRouting does not return turn-by-turn 
directions), but you should be able to modify my code to work with 
pgRouting. I wrote a simple php script to proxy the route request into 
postgres and to format the results back to the client.

Look this over and see how far you can get with this. If you get stuck, 
ask and I'm sure we can get you moving in the right direction.


More information about the mapserver-users mailing list