| 12345678910111213141516171819202122232425262728 |
- import math
- def ggcd(lon1, lat1, lon2, lat2):
- """
- Returns the great-circle distance between two points, in metres
- @param lon1: longitude #1
- @param lat1: latitude #1
- @param lon2: longitude #2
- @param lat2: latitude #2
- @return: the distance between the two points, in metres
- """
- if lat1 == lat2 and lon1 == lon2:
- return 0
- RADIUS = 6371000.0
- rLon1 = math.radians(lon1)
- rLat1 = math.radians(lat1)
- rLon2 = math.radians(lon2)
- rLat2 = math.radians(lat2)
- cosdist = math.cos(rLat1) * math.cos(rLat2) * math.cos(rLon2 - rLon1) + math.sin(rLat1) * math.sin(rLat2)
- if cosdist >= 1.0:
- return 0.0
- else:
- return math.acos(cosdist) * RADIUS
|