1

I'm using Postgis to find angles between sites. End users will use Google Earth to play with these results.

According to st_azimuth, I have exactly 315.002 degrees between these two points :

SELECT degrees(ST_Azimuth( st_setsrid(ST_Point(48.718544, -3.554562),4326), st_setsrid(ST_Point(48.116875, -2.95284),4326) )) AS degA_B

But when I verify them on Google Earth Pro, the result is not just slightly different : the ruler give 326.65° (!) AFAIK, Google Earth is WGS84 based too.

St_distance does'nt much agree with Google earh : the first 94.33333316013 km and the latter 80.37km

Frankly, I'm more confident on Postgis, but I don't know who to believe...

Have I made a mistake?

  • I played with Google Earth and make a line between (0,0) and (45,45), the result is 234.61° So it looks Google Earth is wrong (?) – Ontologiae Jul 13 '16 at 18:32
  • 1
    I read a book on projections once, which I can no longer find, and vaguely recall the author saying the Google Earth uses some kind of projection similar to polar stereographic (as it is looking at the earth from above). It uses, WGS84, as a datum, but that it no way makes the projection 4326. That might explain the strange answers you are seeing. It is quite hard to get reliable information about something that is closed source. Postgis is almost certainly right. – John Powell Jul 13 '16 at 20:12
  • I found an old web site with some javascript code which gives the same result than GE : williams.best.vwh.net/gccalc.htm So the formula is : d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2)) angle = acos( (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)) ) – Ontologiae Jul 14 '16 at 9:56
  • Nice bit of archaeology :D – John Powell Jul 14 '16 at 10:04
  • Very nice. Since the formula is very simple, it's probably azimuth-over-sphere, while postgis is azimuth-over-spheroid, so the questioner is right to prefer the PostGIS answer. Should turn your comment into an answer. – Paul Ramsey Jul 14 '16 at 13:03
1

Discussion in this thread and research in the code permitted to understand the difference between the two bearing calculation algorithms :

  • st_azimuth of Postgis consider the Earth as a spheroid
  • The angle calculation from Google Earth considers the Earth as a perfect sphere. It's a very simple formula :

    d=acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon1-lon2));

    angle = acos( (sin(lat2)-sin(lat1)*cos(d))/(sin(d)*cos(lat1)) );

Thus st_azimuth is more accurate than Google Earth

| improve this answer | |
0

Are your points in Europe? If so, then you've just transposed the coordinates, so try:

SELECT degrees(ST_Azimuth(
    ST_SetSRID(ST_MakePoint(-3.554562, 48.718544), 4326), 
    ST_SetSRID(ST_MakePoint(-2.95284, 48.116875), 4326)
   )) AS degA_B;
| improve this answer | |
  • 2
    This gives 134.99 degrees which is completely different to the Google Earth answer also, so I doubt that is the explanation. – John Powell Jul 13 '16 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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