[pgrouting-users] Directions Start and End Points

Daniel Kastl daniel at georepublic.de
Mon Nov 14 19:32:14 EST 2011


Hi,

When you run your routing query you unfortunately don't know yet which
direction it will take. So when you start from the nearest road link, it's
either "too much" or a small part is missing.
The workshop example is kept very simple. There are other PostGIS
functions, that can help you to locate the nearest point on the road link
and then return a substring:

   - http://postgis.refractions.net/docs/ST_Line_Locate_Point.html
   - http://postgis.refractions.net/docs/ST_Line_Substring.html

So after you got your route you need to check which direction it went and
which substring to add.

Daniel



On Tue, Nov 15, 2011 at 3:09 AM, John Williams <jdwilliams1982 at gmail.com>wrote:

> 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.
>
> _______________________________________________
> Pgrouting-users mailing list
> Pgrouting-users at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/pgrouting-users
>
>


-- 
Georepublic UG & Georepublic Japan
eMail: daniel.kastl at georepublic.de
Web: http://georepublic.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20111115/96e794f9/attachment.html


More information about the Pgrouting-users mailing list