# How to findout direction PostGIS

I want to find out the direction from the 2 points from postGIS database. Please see the attached image. I want to find out the direction from the mainPt to any point. But want to get the result as NW, NE, SE or SW. Simply if I get the degree of the angle it can easily be solved.

Thanks

-

You could use ST_Azimuth for that : http://postgis.net/docs/ST_Azimuth.html

This will give you an angle in radians and the 0 rad angle stands for a point in the north of your main point

-
Angle is computed clockwise from down-to-up: on the clock: 12=0; 3=PI/2; 6=PI; 9=3PI/2 – simplexio Mar 14 '13 at 9:44
SELECT ST_Azimuth(ST_Point(90.420408,23.788879), ST_Point(90.419745,23.79009))/(2*pi())*360 as degAz; returning 331.300114079087. But from the Map I am observing that the second point is located NW from the first point. How can I understand the direction? – Devils Dream Mar 14 '13 at 10:17
According to your example : (0-90°)>NE ; (90-180°)>SE ; (180-270°)>SW ; (270-360°)>NW – FredB Mar 14 '13 at 10:42