[OpenLayers-Users] pgrouting using openlayers

Stephen Woodbridge woodbri at swoodbridge.com
Mon Aug 15 21:05:37 EDT 2011


On 8/15/2011 7:02 PM, Robert Sanson wrote:
> What happens when your click point for a start or end is not directly on
> a node? Does pgrouting snap the start/end points to the nearest vertex
> on the nearest road?

I take the start and end points and in PHP connect to the database and 
snap it to the nearest edge like this:

     $sql = "SELECT gid, source, target, the_geom,
         distance(the_geom, setsrid(makepoint(".
                     $lonlat[0].",".$lonlat[1]."), 4326)) AS dist
             FROM ".TABLE."
             WHERE the_geom && expand(setsrid(makepoint(".
             $lonlat[0].",".$lonlat[1]."),4326), ".$EXPAND.")
             ORDER BY dist LIMIT 1";

You can write some simple functions in plpgsql like:

find_nearest_link_within_distance()
find_nearest_node_within_distance()
find_node_by_nearest_link_within_distance()

I have these on one database, but I can remember if I wrote these or 
they are part of pgRouting as I try to encapsulate most code in simple 
function calls so it is reusable.

-Steve

> Thanks,
> Robert
>
>  >>> Stephen Woodbridge <woodbri at swoodbridge.com> 16/08/2011 6:43 a.m. >>>
> On 8/15/2011 1:57 PM, sushma wrote:
>  > Hi Guys,
>  >
>  > I want to implement pgrouting using openlayers .i.e to find shortest path
>  > from building to another buildings.So if user clicks one building as
> a start
>  > point and another as end point then it returns the shortest path between
>  > those buildings. I am totally new to the openlayers.
>  > So far i can display the map of road data and buildings from
> geoserver using
>  > openlayers. Now i wanted to get on with click control. So need some
>  > suggestion how can i get on with click control.
>
>
> Here is an example that I put together using mapserver for the maps,
> pgRouting and I use a small PHP program to handle the the Ajax requests
> to communicate between OpenLayers and pgRouting.
>
> http://tinyurl.com/3vnufmh
>
> -Steve
> _______________________________________________
> Users mailing list
> Users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/openlayers-users
>
>
> This email and any attachments are confidential and intended solely for
> the addressee(s). If you are not the intended recipient, please notify
> us immediately and then delete this email from your system.
>
> This message has been scanned for Malware and Viruses by Websense Hosted
> Security. www.websense.com <http://www.websense.com/>
>



More information about the Users mailing list