MCPcopy Create free account
hub / github.com/Yasoz/DiffTraj / distance

Function distance

utils/utils.py:90–103  ·  view source on GitHub ↗

Calculate the great circle distance between two points on the earth (specified in decimal degrees)

(lat1, lon1, lat2, lon2)

Source from the content-addressed store, hash-verified

88
89# calculte the distance between two points
90def distance(lat1, lon1, lat2, lon2):
91 """
92 Calculate the great circle distance between two points
93 on the earth (specified in decimal degrees)
94 """
95 # convert decimal degrees to radians
96 lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
97 # haversine formula
98 dlon = lon2 - lon1
99 dlat = lat2 - lat1
100 a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
101 c = 2 * asin(sqrt(a))
102 r = 6371 # Radius of earth in kilometers. Use 3956 for miles
103 return c * r * 1000

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected