Thanks Steve... I really appreciate it. That did the trick. When I test this and get the code cleaned up I&#39;ll post it online for anyone who is interested.<br><br><div class="gmail_quote">On Wed, Oct 19, 2011 at 1:06 PM, Stephen Woodbridge <span dir="ltr">&lt;<a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div><div></div><div class="h5">On 10/19/2011 11:50 AM, John Williams wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I&#39;m trying to implement text-based driving directions in PHP and I&#39;ve<br>
run into a little issue. I&#39;ve read online that you have to check each<br>
segment as you loop through them and make sure the endpoints are lined<br>
up with the direction that you&#39;re traveling, but I&#39;m still confused on<br>
how to do this. Right now I&#39;m pulling source and target from the ways<br>
table. Then, if the current segment&#39;s target does not equal the next<br>
segment&#39;s source I flip the lat/lon values. Can anyone give me a<br>
simplified explanation of how to go about doing this? Thanks...<br>
</blockquote>
<br></div></div>
The key to this is to get the first segment correct. So in pseudocode:<br>
<br>
## check first segment<br>
if (seg[0][source] == seg[1][source] or<br>
    seg[0][source] == seg[1][target]) ) then<br>
  seg[0] = flipsegment(seg[0]);<br>
end if<br>
<br>
## check the rest of the segments<br>
for (i=1; i&lt;count(seg); i++) {<br>
  if (seg[i-1][target] == seg[i][target]) then<br>
    seg[i] = flipsegment(seg[i]);<br>
  end if<br>
end for<br>
<br>
so flipsegment needs to swap source and target AND needs to reverse the order of the points in the linestring.<br>
<br>
-Steve<br>
______________________________<u></u>_________________<br>
Pgrouting-users mailing list<br>
<a href="mailto:Pgrouting-users@lists.osgeo.org" target="_blank">Pgrouting-users@lists.osgeo.<u></u>org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/pgrouting-users" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/pgrouting-<u></u>users</a><br>
</blockquote></div><br>