[OpenLayers-Users] pgrouting using openlayers
woodbri at swoodbridge.com
Tue Aug 16 14:12:15 EDT 2011
On 8/16/2011 8:47 AM, Sush Pokharel wrote:
> Thanks Stephen,
> I have written a simple Pl/pgsql function to find the nearest edge
> between the buildings and the another PL/pgsql function to find the
> shortest route
> where the nearest edge function are passed as a variable and then
> returns the route based on those variables.
> So can you please suggest me how can we integrate this Pl/pgsql function
> in OpenLayer .
Please remember to reply all or to reply to the list.
You have to use an Ajax handler like a PHP script as a go between from
OpenLayers and pgRouting. So you send you request to the Ajax handler,
it reads you parameters, opens a connection to postgresql and issues
some queries to get the route information. Then it formats the data into
XML or GeoJSON or whatever and returns it back to OpenLayers. Then you
have to parse the results and create OpenLayers features and add them to
Look at the source on my page and look at the example demo link the
Daniel posted to the list.
> *From:* Stephen Woodbridge <woodbri at swoodbridge.com>
> *To:* Robert Sanson <Robert.Sanson at asurequality.com>
> *Cc:* openlayers-users at lists.osgeo.org
> *Sent:* Tuesday, 16 August 2011, 2:05
> *Subject:* Re: [OpenLayers-Users] pgrouting using openlayers
> 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.",".$lonlat."), 4326)) AS dist
> FROM ".TABLE."
> WHERE the_geom && expand(setsrid(makepoint(".
> $lonlat.",".$lonlat."),4326), ".$EXPAND.")
> ORDER BY dist LIMIT 1";
> You can write some simple functions in plpgsql like:
> 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.
> > Thanks,
> > Robert
> > >>> Stephen Woodbridge <woodbri at swoodbridge.com
> <mailto: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
> > > 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 <mailto: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/>
> Users mailing list
> Users at lists.osgeo.org <mailto:Users at lists.osgeo.org>
More information about the Users