Hi,<div><br></div><div>When you run your routing query you unfortunately don&#39;t know yet which direction it will take. So when you start from the nearest road link, it&#39;s either &quot;too much&quot; or a small part is missing.</div>

<div>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:</div><div><ul><li><a href="http://postgis.refractions.net/docs/ST_Line_Locate_Point.html">http://postgis.refractions.net/docs/ST_Line_Locate_Point.html</a></li>

<li><a href="http://postgis.refractions.net/docs/ST_Line_Substring.html">http://postgis.refractions.net/docs/ST_Line_Substring.html</a></li></ul></div><div>So after you got your route you need to check which direction it went and which substring to add.</div>

<div><br></div><div>Daniel</div><div><br></div><div><br><br><div class="gmail_quote">On Tue, Nov 15, 2011 at 3:09 AM, John Williams <span dir="ltr">&lt;<a href="mailto:jdwilliams1982@gmail.com">jdwilliams1982@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">This may be obvious, but for whatever reason, I&#39;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&#39;m using the sample &quot;findNearestEdge&quot; function from pgrouting&#39;s website, which looks like this:<br>


<br>function findNearestEdge($lonlat) {<br><br>   $con = pg_connect(&quot;dbname=&quot;.PG_DB.&quot; host=&quot;.PG_HOST.&quot; user=&quot;.PG_USER);<br><br>   $sql = &quot;SELECT gid, source, target, the_geom,<br>           distance(the_geom, GeometryFromText(<br>


                  &#39;POINT(&quot;.$lonlat[0].&quot; &quot;.$lonlat[1].&quot;)&#39;, 4326)) AS dist<br>            FROM &quot;.TABLE.&quot;<br>            WHERE the_geom &amp;&amp; setsrid(<br>                  &#39;BOX3D(&quot;.($lonlat[0]-0.1).&quot;<br>


                         &quot;.($lonlat[1]-0.1).&quot;,<br>                         &quot;.($lonlat[0]+0.1).&quot;<br>                         &quot;.($lonlat[1]+0.1).&quot;)&#39;::box3d, 4326)<br>            ORDER BY dist LIMIT 1&quot;;<br>


<br>   $query = pg_query($con,$sql);<br><br>   $edge[&#39;gid&#39;]      = pg_fetch_result($query, 0, 0);<br>   $edge[&#39;source&#39;]   = pg_fetch_result($query, 0, 1);<br>   $edge[&#39;target&#39;]   = pg_fetch_result($query, 0, 2);<br>


   $edge[&#39;the_geom&#39;] = pg_fetch_result($query, 0, 3);<br><br>   pg_close($con);<br><br>   return $edge;<br>}<br><br><br>What I&#39;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...<br>


<br>My lack of expertise with pgrouting keeps me from understanding some other posts I&#39;ve seen about this topic. Could someone point me in the right direction... thanks a lot.<br>
<br>_______________________________________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org">Pgrouting-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/pgrouting-users" target="_blank">http://lists.osgeo.org/mailman/listinfo/pgrouting-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><span style="font-family:arial, sans-serif;font-size:13px;border-collapse:collapse">Georepublic UG &amp; Georepublic Japan<br>eMail: <a href="mailto:daniel.kastl@georepublic.de" style="color:rgb(66, 99, 171)" target="_blank">daniel.kastl@georepublic.de</a><br>

Web: <a href="http://georepublic.de/" style="color:rgb(66, 99, 171)" target="_blank">http://georepublic.de</a></span><br>
</div>