summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gps/misc.py18
-rwxr-xr-xgpsprof16
2 files changed, 18 insertions, 16 deletions
diff --git a/gps/misc.py b/gps/misc.py
index 0b343d6a..c5fac25e 100644
--- a/gps/misc.py
+++ b/gps/misc.py
@@ -146,6 +146,24 @@ def EarthDistance(c1, c2):
a = -1
return CalcRad((lat1 +lat2) / 2) * math.acos(a)
+def EarthDistanceSmall(c1, c2):
+ "Distance in meters between two close points specified in degrees."
+ # This calculation is known as an Equirectangular Projection
+ # fewer numeric issues for small angles that other methods
+ (lat1, lon1) = c1
+ (lat2, lon2) = c2
+ avglat = (lat1 + lat2 ) /2
+ phi = math.radians( avglat ) # radians of avg latitude
+ # meters per degree at this latitude, corrected for WGS84 ellipsoid
+ # Note the wikipedia numbers are NOT ellipsoid corrected:
+ # https://en.wikipedia.org/wiki/Decimal_degrees#Precision
+ m_per_d = (111132.954 - 559.822 * math.cos(2 * phi)
+ + 1.175 * math.cos(4 * phi))
+ dlat = (lat1 - lat2) * m_per_d
+ dlon = (lon1 - lon2) * m_per_d * math.cos( phi )
+
+ dist = math.sqrt( math.pow(dlat, 2) + math.pow(dlon, 2 ))
+ return dist;
def MeterOffset(c1, c2):
"Return offset in meters of second arg from first."
diff --git a/gpsprof b/gpsprof
index 31cbe6bd..9940056c 100755
--- a/gpsprof
+++ b/gpsprof
@@ -20,22 +20,6 @@ import socket
import sys
import time
-def EarthDistanceSmall(c1, c2):
- "Distance in meters between two close points specified in degrees."
- # This calculation is known as an Equirectangular Projection
- # fewer numeric issues for small angles that other methods
- (lat1, lon1) = c1
- (lat2, lon2) = c2
- dlat = lat1 - lat2
- avglat = (lat1 + lat2 ) /2
- dlon = (lon1 - lon2) * math.cos( math.radians( avglat ) )
- # Earth Mean Radius 6371000 meters.
- # one degree lat, average 111.133000
- # at equator 110.567 km
- # at poll 111.699 km
- dist = math.sqrt( dlat * dlat + dlon * dlon) * 111133
- return dist;
-
class Baton(object):
"Ship progress indication to stderr."