PostGIS – How to Find Out Direction in PostGIS

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.

Thanksenter image description here

Best Answer

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

Related Question