[pgrouting-users] Question about driving directions
John Williams
jdwilliams1982 at gmail.com
Wed Oct 19 15:47:46 EDT 2011
Thanks Steve... I really appreciate it. That did the trick. When I test this
and get the code cleaned up I'll post it online for anyone who is
interested.
On Wed, Oct 19, 2011 at 1:06 PM, Stephen Woodbridge <woodbri at swoodbridge.com
> wrote:
> On 10/19/2011 11:50 AM, John Williams wrote:
>
>> I'm trying to implement text-based driving directions in PHP and I've
>> run into a little issue. I've read online that you have to check each
>> segment as you loop through them and make sure the endpoints are lined
>> up with the direction that you're traveling, but I'm still confused on
>> how to do this. Right now I'm pulling source and target from the ways
>> table. Then, if the current segment's target does not equal the next
>> segment's source I flip the lat/lon values. Can anyone give me a
>> simplified explanation of how to go about doing this? Thanks...
>>
>
> The key to this is to get the first segment correct. So in pseudocode:
>
> ## check first segment
> if (seg[0][source] == seg[1][source] or
> seg[0][source] == seg[1][target]) ) then
> seg[0] = flipsegment(seg[0]);
> end if
>
> ## check the rest of the segments
> for (i=1; i<count(seg); i++) {
> if (seg[i-1][target] == seg[i][target]) then
> seg[i] = flipsegment(seg[i]);
> end if
> end for
>
> so flipsegment needs to swap source and target AND needs to reverse the
> order of the points in the linestring.
>
> -Steve
> ______________________________**_________________
> Pgrouting-users mailing list
> Pgrouting-users at lists.osgeo.**org <Pgrouting-users at lists.osgeo.org>
> http://lists.osgeo.org/**mailman/listinfo/pgrouting-**users<http://lists.osgeo.org/mailman/listinfo/pgrouting-users>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/pgrouting-users/attachments/20111019/cd23de65/attachment.html
More information about the Pgrouting-users
mailing list