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…
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
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@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 ifcheck 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 forso 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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users
Thank you!
If you have some example and want to share it, you’re welcome to add it to the website, which has it’s repository here:
https://github.com/pgRouting/website … and/or add some sample code to this repository: https://github.com/pgRouting/pgrouting-contrib
Even if it may be specific for some particular data, I’m sure a lot of users would appreciate.
Daniel
On Thu, Oct 20, 2011 at 4:47 AM, John Williams <jdwilliams1982@gmail.com> wrote:
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@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 ifcheck 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 forso 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@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users
Pgrouting-users mailing list
Pgrouting-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/pgrouting-users
–
Georepublic UG & Georepublic Japan
eMail: daniel.kastl@georepublic.de
Web: http://georepublic.de