Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

Thanksenter image description here

share|improve this question
up vote 8 down vote accepted

You could use ST_Azimuth for that :

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

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.