<div dir="ltr">Thanx Steve, your information were helpful, but when I think of it it confuses me a lot, lets first start with my fields in DB.<div><br></div><div>Columns are:</div><div><div>  gid serial NOT NULL,</div><div>
  rod_name_a character varying(50),</div><div>  label character varying(50),</div><div>  rod_length integer,</div><div>  rod_no integer,</div><div>  rod_type character varying(1),</div><div>  rod_class character varying(1),</div>
<div>  rod_code character varying(10),</div><div>  shape_leng numeric,</div><div>  the_geom geometry,</div><div>  source integer,</div><div>  target integer,</div><div>  length double precision,</div><div>  x1 double precision,</div>
<div>  y1 double precision,</div><div>  x2 double precision,</div><div>  y2 double precision,</div><div>  to_cost double precision,</div><div>  "rule" text,</div><div>  cost_factor integer,</div><div>  main_cost double precision,</div>
<div>  reverse_cost double precision,</div><div>  roadclass text DEFAULT 'OTHER'::text,</div><div>  cost_reverse_factor integer DEFAULT 5,</div><div><br></div><div>Now, I am confused, because I cannot calculate the heading in the first place, If I have</div>
<div>B+---\</div><div>x2,y2<br>    |</div><div>x1,y1<br>A+---/<br></div><div><br></div><div>Now I can calculate the heading simply by comparing x1 and y1 to x2 to y2 and which is larger (based on lonlat) so I can judge it, but some times I am having this:</div>
<div><div>B+---\</div><div>x1,y1<br>    |</div><div>x2,y2<br>A+---/</div><div><br></div><div>Now it is misleading, maybe thats why you told me not to use start and end point, but wait, what else to use ? According to my DB I cannot think of any other way to calculate headings and angles.</div>
<div><br></div><div>Regards</div></div><br><div class="gmail_quote">On Wed, Dec 31, 2008 at 7:45 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div class="Ih2E3d">Ahmad Bdair wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Yes, that is something very similar to what I need to do, I already wrote a php code to check angels and slopes, but it was not accurate, it was more life "if else" code, I check the longlat for current segment <br>

</blockquote>
<br></div>
When you check the angles do not use the end points because they are mis-leading.<br>
<br>
B+---\<br>
     |<br>
A+---/<br>
<br>
If you have a segment from A to B like the above and you calculate the heading or angles based on the vector AB then it will point north and is should be pointing west at the end of the vector or east at the start of the vector.<br>

<br>
You also need to look at weather or not you need to flip segments because you route might traverse them from start to end OR from end to start.<br>
<br>
When I compute angles I grid the angles into 8 pie pieces of 45 degrees each.<br>
<br>
continue straight<br>
turn slight right/left<br>
turn right/left<br>
turn sharp right/left<br>
make a u-turn<div class="Ih2E3d"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
with longlat for the previous one, I guess you didn't use the database for direction calculation(except for routing) am I right? Isn't steps 3 and 4 depends on your angel calculations?<br>
</blockquote>
<br></div>
I have done this in C in a prototype router I wrote years ago. I have implemented it in PHP and in perl in various incarnations in the past. The demo page has it written in pgpsql, but it is based on my own heavily modified versions of the pgRouting stored procedures.<br>

<br>
Hope the above helps with your problems. I find it easiest to work out the math problems of computing the angles and headings first and make sure they are correct. Then move on to the other issues. If your math is wrong computing the headings and angles it will cloud all the other results.<br>

<br>
Best regards,<br>
  -Steve<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="Ih2E3d">
I have the roads with two different languages, a road map like anyother road map I guess.<br>
<br></div><div><div></div><div class="Wj3C7c">
On Tue, Dec 30, 2008 at 3:17 AM, Stephen Woodbridge <<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a> <mailto:<a href="mailto:woodbri@swoodbridge.com" target="_blank">woodbri@swoodbridge.com</a>>> wrote:<br>

<br>
    bdair2002 wrote:<br>
<br>
        Hello,<br>
        I am developing an application using Pgrouting with Postgis<br>
        data, everything<br>
        is fine, but now I am looking  to do something like Google<br>
        directions guide,<br>
        where it tells you turn left or right, I am wondering if this<br>
        feature is a<br>
        built-in feature in Pgrouting or Postgis.<br>
<br>
        Regards<br>
<br>
<br>
    No this is not a feature that is part of either.<br>
<br>
    I have implemented a directions explicator, but it is somewhat<br>
    specific to the data that you have, as you need to know what<br>
    column(s) contain the road names, if you have signage information<br>
    then you need to know how to link to that. If you want to be able to<br>
    explicate in multiple languages, then you probably need to consider<br>
    supporting multiple languages each in a separate table the you can<br>
    select from when you generate the languages.<br>
<br>
    The algorithm is pretty straight forward as the you currently get a<br>
    list of segments that make up the route. Then you need to:<br>
<br>
    analyze each segment and<br>
    1) check to see if you want to join it with the previous segment<br>
    because the road name matches<br>
    2) check the angle that it makes with the last segment to determine<br>
    right, left, straightness of turn<br>
    3) compute the compass heading for the segment<br>
    4) determine if you have signage<br>
    5) based on these, determine if you are read to explicate and which<br>
    predefined instruction you need to explicate an instruction<br>
    6) loop through all segments<br>
<br>
    For a demo of this you can try:<br>
    <a href="http://imaptools.com/leaddog/routing/dd.html" target="_blank">http://imaptools.com/leaddog/routing/dd.html</a><br>
<br>
    Zoom into a city in one of the yellow areas, set a start and end<br>
    point and click [calculate route] button. The driving directions<br>
    should show below the button if it was successful, be patience the<br>
    routing is running on a 333MHz box.<br>
<br>
    -Steve<br>
<br>
    _______________________________________________<br>
    postgis-users mailing list<br>
    <a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br></div></div>
    <mailto:<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a>><div class="Ih2E3d"><br>
    <a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
<br>
<br>
<br></div>
------------------------------------------------------------------------<div class="Ih2E3d"><br>
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></blockquote><div><div></div><div class="Wj3C7c">
<br>
_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@postgis.refractions.net" target="_blank">postgis-users@postgis.refractions.net</a><br>
<a href="http://postgis.refractions.net/mailman/listinfo/postgis-users" target="_blank">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br>
</div></div></blockquote></div><br></div></div>