4

I am comparing the various ways of calculating distance and azimuth between two points with Qgis. I am struggling with the various results and their interpretation.

I need to calculate a loxodromic bearing (rhumb line, i.e. a path beetween two points with constant bearing) : which function should I use ? According to my partial conclusions from the data below, none of them returns loxodromic bearing !

  • the bearing and measureLine functions compute orthodromic route and distance (both from the function computeDistanceBearing that uses a Vincenty algorithm which indeed aims to calculate a great circle distance and bearing, according to Wikipedia page)
  • the azimuth function computes a calculation with a "flat" formula according to api documentation (note that the computeDistanceFlat function returns the square root of the distance when the coordinates are in degrees and the distance when the coordinates are in meters and Mercator system, cf. numeric example below)
  • since my loxodromic calculation seems to be wrong, I don't know if one is close to loxodromic figures

Below are some results of functions and my partial conclusions with the example of New-York (-74,40.73) and Paris (2.34,48.86) - coordinates in long/lat or EPSG 4326.


The results of the various functions are :

tool                                  distance ParistoNY   NYtoParis
tool.bearing(p1,p2)                       -       292        54
tool.measureLine(p1,p2)                 5850       -         - 
tool.computeDistanceFlat(p1,p2)           76       -         -
pow(tool.computeDistanceFlat(p1,p2),2)  5893       -         -
p1.azimuth(p2), p2.azimuth(p1)            -       264        84

after conversion of coordinates into Mercator system:

tool                          distance   ParistoNY   NYtoParis
p1.azimuth(p2), p2.azimuth(p1)    -         261          81
tool.computeDistanceFlat(p1,p2)  8593130

Manual calculation from wikipedia formulas for a sphere :

tool                                    distance   ParistoNY   NYtoParis
orthodromic distance and initial route    5830         54          292   
loxodromic distance and route          344017235       89           89
manual flat azimuth on epsg4326             -         264           84
0

1 Answer 1

1

I finally found a solution.
1) Qgis does not provide a simple function to compute loxodromic bearing or distance ; the measureLine and bearing functions (and the measuring tool of the graphical interface) provide the orthodromic figures ((great circle); if no ellipsoid is set to QgsDistanceArea or if the flag ellipsoidalEnabled is False, the same functions compute "flat calculation" with no warning ; the QgsPoint functions sqrDist and azimuth provide "flat calculation" only.

2) I have found 2 solutions to compute loxodromic bearing and distance :
- implementing formulas found on french wikipedia "loxodromie". This is only an approximate solution based on a sphere model of the earth. This is not straighforward because all coordinates must be in radians, even the ones that are not behind a trigonometry function ; the final distance is in radians and must be converted in meters with : d_meters=d_radians/pi ; the calculated azimuth is always between 0 and 180° because tangent has a pi period, then the final azimuth must be calculated as : if lon2>lon1: azimuth=azimuth+180
- Using the properties of Mercator projection : in Mercator projection, a loxodromic line is straight ; then, the azimuth can be calculated with the "flat" formula, for example with qgsPoint.azimuth function. However the distance cannot becalculated the same way : the distance in radians can be calculated with: d_radians=(lat2-lat1)/cos(azimuth), with lat1,lat2 and azimuth in radians. Conversion in meters: d_meters=d_radians/pi

There is a C++ library geographiclib that computes orthodrome, loxodrome (both in direct and reverse ways) and much more and it has been partially translated into python. But unfortunatly, not the rhumb class. Does anyone know about another library that would do that ?

1
  • loxodrome = rhumb line
    – mkennedy
    Commented Feb 2, 2016 at 20:19

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.