[pgrouting-users] Directions Start and End Points

John Williams jdwilliams1982 at gmail.com
Mon Nov 14 13:09:14 EST 2011


This may be obvious, but for whatever reason, I'm not able to figure it
out. When calculating driving directions with pgrouting, to find the
starting and ending points for the path finding algorithm, I'm using the
sample "findNearestEdge" function from pgrouting's website, which looks
like this:

function findNearestEdge($lonlat) {

   $con = pg_connect("dbname=".PG_DB." host=".PG_HOST." user=".PG_USER);

   $sql = "SELECT gid, source, target, the_geom,
           distance(the_geom, GeometryFromText(
                  'POINT(".$lonlat[0]." ".$lonlat[1].")', 4326)) AS dist
            FROM ".TABLE."
            WHERE the_geom && setsrid(
                  'BOX3D(".($lonlat[0]-0.1)."
                         ".($lonlat[1]-0.1).",
                         ".($lonlat[0]+0.1)."
                         ".($lonlat[1]+0.1).")'::box3d, 4326)
            ORDER BY dist LIMIT 1";

   $query = pg_query($con,$sql);

   $edge['gid']      = pg_fetch_result($query, 0, 0);
   $edge['source']   = pg_fetch_result($query, 0, 1);
   $edge['target']   = pg_fetch_result($query, 0, 2);
   $edge['the_geom'] = pg_fetch_result($query, 0, 3);

   pg_close($con);

   return $edge;
}


What I'd like to do is adjust the starting and ending points so they match
up exactly with my lat/lon beginning/ending points. For example, the way it
works now if my destination is mid-way down a particular street and I plot
the route on a map, it may look like the route takes you to the end of the
block, when it should have stopped earlier, or vice-versa. I hope that
makes sense...

My lack of expertise with pgrouting keeps me from understanding some other
posts I've seen about this topic. Could someone point me in the right
direction... thanks a lot.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20111114/627aa49f/attachment.html


More information about the Pgrouting-users mailing list