2

I'm trying to calculate distance between 2 locations. Each location has lat, lon, altitude. When calculating distance using Geopy it doesn't seem to consider the altitude: slight changes in lat, lot influence the result, small/huge change in altitude doesn't affect the resulting distance. What am I doing wrong? How to calculate geo distance considering the altitude? Thanks!

import geopy

p1 = geopy.point.Point()
p1.latitude = 10
p1.longitude = -110

p2 = geopy.point.Point()
p2.altitude = 35
p2.latitude = 20
p2.longitude = -120

# low alt
p1.altitude = 350 
print(geopy.distance.geodesic(p1, p2).km)
# 1541.8564339502925

# high alt
p1.altitude = 3500000 
print(geopy.distance.geodesic(p1, p2).km)
# 1541.8564339502925
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
cs_student
  • 31
  • 3
  • seems like `geopy.distance.geodesic` is indeed ignoring the specified altitude. As a workaround, you could add the calculation of the Euclidean distance as shown [here](https://stackoverflow.com/a/42394979/10197418). – FObersteiner Jan 09 '20 at 14:40
  • thanks! euclidean distance isn't good enough for this task. eventually i have wrote a learning based algorithm that considers altitude as well. – cs_student Jan 21 '20 at 12:24
  • Maybe open an issue on the [geopy github page](https://github.com/geopy/geopy/issues)? I think the option to include altitude information can lead to the false assumption that this would be included in the distance calculation - despite the fact that there's not only one way to include it in the calculation... So this should at least be clarified in the docs. – FObersteiner Jan 22 '20 at 09:00
  • For reference: https://github.com/geopy/geopy/issues/387 – KostyaEsmukov Dec 20 '20 at 17:09

0 Answers0