[pgrouting-users] problem with azimuth()

Stephen Woodbridge woodbri at swoodbridge.com
Mon Apr 6 12:17:22 EDT 2009


Valeria Muñoz wrote:
> Hi
>  
> After a while I returned to my work pgrouting. I'm trying to define 
> whether a user should turn right or left with the function azimuth .
>  
> My problem is: does not work:) I'm doing something wrong.
>  
> My query:
>  
> A-SELECT azimuth(startpoint(the_geom),endpoint(the_geom)) as azimuth 
> from calle where gid = 4390
> B-SELECT azimuth(startpoint(the_geom),endpoint(the_geom)) as azimuth 
> from calle where gid = 7326
> C-SELECT azimuth(startpoint(the_geom),endpoint(the_geom)) as azimuth 
> from calle where gid = 4392
> D-SELECT azimuth(startpoint(the_geom),endpoint(the_geom)) as azimuth 
> from calle where gid = 4402
>  
> After obtaining the results:
> I compare A con B if the result is <=-1=turn left >=1 tunr right
> I compare B con C if the result is <=-1=turn left >=1 tunr right
> I compare C con D if the result is <=-1=turn left >=1 tunr right
> 
>  
> can someone please guide me?
> RG

Valeria,

Azimuth() gives you a heading. a heading is like north only azimuth 
gives it in degrees (or maybe radians).

So if you were going the equivalent of north at A and you are now going 
the equivalent of east ad B then your would make a Right turn.

You have to allow for the fact that these are angles because you might 
have been going some degrees east or west of north at A and likewise at B.

If I have a segment X--------Y azimuth will return different values for 
azimuth(X, Y) vs azimuth(Y, X). so you have to look at the segment in 
the route and at its end points to figure out whether you are going X_Y 
or Y-X.

-Steve



More information about the Pgrouting-users mailing list