3

I do not understand the function behaviour. I am giving the function a point B that is North of point A so I would expect something around 90 degrees but I get 263 degrees instead. In another example, I keep the same point A and I am giving the function a point B that is on the South of point A and this time I do get a correct value of 279 degrees.

The function definition states that it is using the horizontal of the vector between A and B. But I don't understand the part which says:

Angle is computed clockwise from down-to-up: on the clock: 12=0; 3=PI/2; 6=PI; 9=3PI/2.

Here are the examples, maybe I am doing something wrong with the SQL point b NE of point A:

SELECT degrees(
                ST_Azimuth(
                    ST_Transform(ST_GeomFromText('POINT(127.702 38.169)',4326),32652),
                    ST_Transform(ST_GeomFromText('POINT(126.728 38.178)',4326),32652)
                           )
                )

This returns 271 degrees whilst it should return ~45 degrees

Someone care to explain? Thanks in advance!

3 Answers 3

1

A point to the north will give an azimuth near 0 or 360.

When it is exactly to the north it will be 0 as it moves to the east it will become larger until is is 45 a NorthEast of your point, if you pull it down level with you and east it will be 90 or level and to the west will be 270. As it moves below you it will fall between 90 and 270 depending on how much to the east or west the point is.

Looking at your query I would say that the second point is west of the first one so 270 is about right.

1

There is a extract from my system :

SELECT degrees( 
    ST_Azimuth(u1.the_geom, u2.the_geom ) ) 
from units as u1, units as u2 where u1.serial='SOURCE' and u2.serial='TARGET' 

The behaviour of the function is : "what is the azimuth (bearing) of TARGET given a SOURCE?"

Consider NORTH is azimuth ZERO. So, SOUTH is 180, WEST is 270 and EAST is 90.

1

If you plot your coordinates assuming that latitude and longitude form a cartesian coordinate system (everything meets at right angles and the x and y axis are straight lines) then you would expect ST_Azimuth to give your anticipated ~45 degrees. However, lines of latitude and longitude aren't straight and they don't form a cartesian coordinate system. So, by taking into account the curvature of the earth ST_Azimuth gets the correct answer of 271.

To verify this try typing your coordinates into Google Earth.

1
  • 1
    In practice, this means that you'll very often want to use ST_Azimuth(SOME_GEOMETRY::geography, OTHER_GEOMETRY::geography) to mitigate the effects of the projection. Commented Jan 7, 2015 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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