Hey Thank you Stephen for you suggestions.<br><br>Well, it is about 5 and half day that I am trying to implement the suggestions that Stephen gave me. But no solution yet.<br>The thing is I am trying to implement his suggestion from the message below on the pgrouting foss4g2010 workshop in order to see how it works.<br>
I tried to combine the pgrouting workshop from : <a href="http://www.pgrouting.org/docs/ol-workshop/index.html">http://www.pgrouting.org/docs/ol-workshop/index.html</a> tying to do some minor change but no success. <a href="http://www.pgrouting.org/docs/ol-workshop/ch09.html">http://www.pgrouting.org/docs/ol-workshop/ch09.html</a><br>
<br>Is there anyone working on it or had the chance to get the same result that Stephen got on his tool? <br><a href="http://gis.imaptools.com/routing/leaddog/?zoom=10&lat=33.85667&lon=35.52978&layers=B0TTTF&start=35.492313%2033.826188&stop=35.595811%2033.906827&method=STS&lang=eng" target="_blank">http://gis.imaptools.com/routing/leaddog/?zoom=10&lat=33.85667&lon=35.52978&layers=B0TTTF&start=35.492313%2033.826188&stop=35.595811%2033.906827&method=STS&lang=eng</a>)<br>
<br>I am still having a hard time to implement it. I need to get a GeoJSON file back with the path determined by the pgroutitng.<br>Thanks...<br><br>P.S. The foss4gg2010 is based on OSM in BARCELONA.<br><br><br><br><div class="gmail_quote">
On Tue, Jan 25, 2011 at 2:40 AM, Stephen Woodbridge <span dir="ltr"><<a href="mailto:woodbri@swoodbridge.com">woodbri@swoodbridge.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<div bgcolor="#ffffff" text="#000000"><div class="im">
On 1/24/2011 5:44 PM, Cleber Arruda wrote:
<blockquote type="cite">
Hello,<br>
Hi Stephen how are you? I hope you are fine and enjoying life.<br>
Well, I am doing my master thesis in Sweden in Geomatics as I
mentioned to you on the phone.<br>
My Master thesis topic is the development of routing network using
pgrouting and OSM.<br>
So, I have been looking for the solution for this problem since
October 2010. I have stopped the written part of my thesis and
started the technical part. I have to finish write the application
- the routing using pgrouting - just the one you have on <a href="http://gis.imaptools.com/routing/leaddog/?zoom=10&lat=33.85667&lon=35.52978&layers=B0TTTF&start=35.492313%2033.826188&stop=35.595811%2033.906827&method=STS&lang=eng" target="_blank">http://gis.imaptools.com/routing/leaddog/?zoom=10&lat=33.85667&lon=35.52978&layers=B0TTTF&start=35.492313%2033.826188&stop=35.595811%2033.906827&method=STS&lang=eng</a>).<br>
<br>
I would appreciate if you can guide me through the steps to find
the best route and draw the segment/path correctly from the start
point to the end point.<br>
Well, I am sending you a print screen of what I have got so far.<br>
<br>
</blockquote></div>
Hi Cléber,<br>
<br>
So the process for dealing with the segments is as follows.<br>
<br>
1. we assume that the list of segments is in the correct order from
start to end of the route, but any given segment might be flipped
backwards. For example the segment is loaded as A->B but in the
graph we traverse it from B->A. We will always get the segment in
the result as A->B. So this is the process to flip the segments.
For this pseudo-code I will use the following notation:<br>
<br>
S[n] - segment n<br>
S[n].A - is the point at the start of the segment<br>
S[n].B - is the point at the end of the segment<br>
<br>
A. check if we need to flip the first segment, If the start of the
1st segment is connected to the 2nd segment we need to flip it:<br>
<br>
if (S[0].A == S[1].A or S[0].A == S[1].B) then reverse(S[0]);<br>
<br>
See:<br>
<a href="http://postgis.refractions.net/docs/index.html" target="_blank">http://postgis.refractions.net/docs/index.html</a> -- main postgis
reference manual<br>
<a href="http://www.postgresql.org/docs/" target="_blank">http://www.postgresql.org/docs/</a> -- main
postgresql docs<br>
You might want to look for plpgsql language examples<br>
<br>
<a href="http://postgis.refractions.net/docs/ST_Reverse.html" target="_blank">http://postgis.refractions.net/docs/ST_Reverse.html</a><br>
<a href="http://postgis.refractions.net/docs/ST_Distance.html" target="_blank">http://postgis.refractions.net/docs/ST_Distance.html</a><br>
<a href="http://postgis.refractions.net/docs/ST_StartPoint.html" target="_blank">http://postgis.refractions.net/docs/ST_StartPoint.html</a><br>
<a href="http://postgis.refractions.net/docs/ST_EndPoint.html" target="_blank">http://postgis.refractions.net/docs/ST_EndPoint.html</a><br>
<br>
You can translate S[0].A == S[1].A into something like:<br>
<br>
distance(st_startpoint(seg0), st_startpoint(seg1)) < tolerance<br>
<br>
<br>
B. now we need to check the rest of the segments assuming S[0] <br>
<br>
for (i=1; i<count(S); i++) {<br>
if(S[i-1].B == S[i].B) then reverse(S[i]);<br>
}<br>
<br>
2. now all the segments are order correctly from start to finish.
There are some corner cases that you need to check for and deal
with, like the start and end are on the same segment and there is
only one segment in the result. You might need to check for gaps
between the segments, but if the data was prepared correctly you
should not need to worry about this. Now we need to trim the first
and last segments. Look at the postGIS linear referencing functions
for the tools to do this.<br>
<br>
A. first we trim the start, we assume "start" is the start point for
the route. We have already flipped it if that was needed. We can
think of the problem like this:<br>
<br>
A----------P-----------B<br>
<br>
where A->B is S[0] and P is our "start point. We know that the
2nd segment is connected to B so we want P->B:<br>
<br>
<code></code>S[0] = <code><b>ST_Line_Substring</b>(</code>S[0]<var></var><code>, </code><code><b>ST_Line_Locate_Point</b>(</code>S[0]<var></var>, start<var></var><code>)</code><code>, 1.0);<br>
</code><br>
<a href="http://postgis.refractions.net/docs/ST_Line_Substring.html" target="_blank">http://postgis.refractions.net/docs/ST_Line_Substring.html</a><br>
<a href="http://postgis.refractions.net/docs/ST_Line_Locate_Point.html" target="_blank">http://postgis.refractions.net/docs/ST_Line_Locate_Point.html</a><br>
<br>
B. likewise we need to trim the last segment, it has also been
flipped if needed. And this problem is:<br>
<br>
A---------P------------B<br>
<br>
Where A->B is the last segment and the n-1 segment is connect to
A so we want A->P in this case:<br>
<br>
S[n] = <code><b>ST_Line_Substring</b>(</code>S[n]<var></var><code>, 0.0, </code><code><b>ST_Line_Locate_Point</b>(</code>S[n]<var></var>, end<code>)</code><code>);<br>
<br>
So this is the basic algorithm. You can see it is fairly simple
and straight forward. The trick is converting this into plpgsql
language. You typically do not work with arrays in plpgsql, but
with record sets and set returning function. A lot of people that
are more familiar with PHP, get the results back in PHP and post
process the data there.<br>
<br>
See what you can do with this. I'm also going to post this to the
pgRouting list so other can help and learn for this. If you are
not subscribed to the list you should be as there are lots of
people there that can help if I'm not available.<br>
<br>
Thanks for your call today and best regards,<br>
-Steve<br>
<a href="http://imaptools.com/" target="_blank">http://imaptools.com/</a><br>
</code><div class="im"><br>
<blockquote type="cite">Thanks and take care. <br>
I hope that together we strive to achieve excellence for a better
world in this wonderful field and for all newcomer generations.<br>
<span></span><br>
-- <br>
Cléber D. Arruda<br>
Kämnärsvägen 33C<br>
226 46<br>
Lund - Sweden<br>
Phone +46737762526<br>
E-mail: <a href="mailto:cleverdo@gmail.com" target="_blank">cleverdo@gmail.com</a><br>
<br>
Peace and Love Always.<br>
<br>
</blockquote><br></div></div></blockquote></div><br>-- <br>Cléber D. Arruda<br>Kämnärsvägen 33C<br>226 46<br>Lund - Sweden<br>Phone +46737762526<br>E-mail: <a href="mailto:cleverdo@gmail.com" target="_blank">cleverdo@gmail.com</a><br>
<br>Peace and Love Always.<br><br>