I am looking at ways to calculate (in Python) the destination location from a point given bearing and range.
Based on the results comparison from the 2 libraries in subject(geopy
and pyproj
), I noticed that there is an increasing difference in the final output. For instance, at 100 km is roughly of the order of decimeters. This is a minimal example of what I mean:
from __future__ import absolute_import, division, print_function
long_1 = -1.729722
lat_1 = 53.320556
bearing = 96.021667
distance = 124.8 #in km
# using geopy
import geopy
from geopy.distance import VincentyDistance
origin = geopy.Point(lat_1, long_1)
destination = VincentyDistance(kilometers=distance).destination(origin, bearing)
gp_lat_2 = destination.latitude
gp_long_2 = destination.longitude
# using pyproj
from pyproj import Geod
g = Geod(ellps='WGS84')
prj_long_2, prj_lat_2, prj_bearing_2 = g.fwd(long_1, lat_1, bearing, distance*1000)
# results comparison
print(" | pyproj | geopy")
print("long_2 %.6f %.6f" % (prj_long_2, gp_long_2))
print("lat_2 %.6f %.6f" % (prj_lat_2, gp_lat_2))
print("> DELTA pyproj, geopy")
print("delta long_2 %.7f" % (prj_long_2 - gp_long_2))
print("delta lat_2 %.7f" % (prj_lat_2 - gp_lat_2))
I got these results:
| pyproj | geopy
long_2 0.127201 0.127199
lat_2 53.188432 53.188432
> DELTA pyproj, geopy
delta long_2 0.0000021
delta lat_2 -0.0000002
My main question is whether I am doing something wrong (both settings should be using WGS84
).
If not, is the difference due to different formulas in use (Vincenty for geopy
vs. Karney for pyproj
)? E.g., the round-off error cited here.