Is the azimuth at the equator equal to the azimuth not at the equator?

I am trying to fully understand the concept of azimuth and I am running into some inconsistencies (or maybe this is my fault).

I'll show you some examples that don't match, hoping that someone can explain to me how this actually works.

I am displaying coordinates in EPSG: 900913, in PostGIS and using my own JavaScript function.

MY FUNCTION

/* Difference between the two longitudes */
var dLon = lon2 - lon1;
/* Y value */
var y = Math.sin(dLon) * Math.cos(lat2);
/* X value */
var x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
/* Calculates the azimuth between the two points and converts it to degrees */
var angle = Math.atan2(y, x) / Math.PI * 180;

      

<strong> Examples

/* Same Y, not on the equator */
Point A: (-81328.998084106, 7474929.8690234)
Point B: (4125765.0381464, 7474929.8690234)
Result in PostGIS: 90 degrees
Result in my JS function: 74.232 degrees

/* Same Y, on the equator */
Point A: (-81328.998084106, 0)
Point B: (4125765.0381464, 0)
Result in PostGIS: 90 degrees
Result in my JS function: 90 degrees

      

I understand that at the equator the azimuth is 90 (or 270) for the horizontal line. consider that if you draw a horizontal line slightly north (or south) of the equator, the azimuth will not be 90 degrees greater. But ... PostGIS tells me that it is always 90 degrees when we have the same Y.

In addition, this calculator also shows that the azimuths of the horizontal lines are not 90 degrees when Y! = 0 (not at the equator).

How is it correct?

thank

+3


source to share


1 answer


In your example, you used EPSG: 900913, which is flat, projected and in meters. This means that the formula used will be atan2, which will always be 90 when the latitudes are the same, since the formula is:

azimuth = atan2(y1-y2, x1-x2)

And the second part will always be 0 giving an azimuth of 90. So using plane coordinates, yes, the azimuth will always be the same for pairs of coordinates with the same latitude, which is why Postgis always gives the same answer when using EPS: 900913.

If you switch to the geography data type and therefore use geodetic coordinates, this is no longer the case.

For example:

select degrees(   
  st_azimuth(
   st_makepoint(0, 10)::geography, 
   st_makepoint(90, 10)::geography));

      



Gives 80.1318065 in Postgis and gives 80.139 in the calculator page you linked.

As x / longitudes get closer, the closer the values ​​are to 90 for a given latitude. For example,

select degrees(   
  st_azimuth(
   st_makepoint(0, 10)::geography, 
   st_makepoint(1, 10)::geography));

      

Now gives 89.9131737 in Postgis and 89.333 in the online calculator (slightly more discrepancy).

All this is due to the fact that now the formula takes into account the curvature, so the angle between the projections of two vectors with equal width is greater than 90, with the exception of the equator.

Look at the equation in the Wikipedia azimuth article for the spheroid version. This should be simple enough to code in JavaScript and should provide comparable responses to Postgis with a geography type.

+2


source







All Articles