From c2568a4d9da3f3615e7f26357b78fee51599d64b Mon Sep 17 00:00:00 2001 From: Chris Applegate Date: Fri, 2 Mar 2012 00:42:49 +0000 Subject: [PATCH] Use latitude & longitude as separate params for consistency, rounding --- lib/geo.py | 11 ++++++----- whensmytransport.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/geo.py b/lib/geo.py index 45fff7f..9e6cc4a 100644 --- a/lib/geo.py +++ b/lib/geo.py @@ -315,14 +315,15 @@ def convert(lat, lon, height, e1, t, e2): Lambda = math.atan2(y2, x2) H = p/math.cos(phi) - nu - return (math.degrees(phi), math.degrees(Lambda), H) + # Rounding to 7 decimal places in a degree gives us about +/- 0.01m accuracy + return (round(math.degrees(phi), 7), round(math.degrees(Lambda), 7), H) -def convertWGS84toOSEastingNorthing(position): +def convertWGS84toOSEastingNorthing(latitude, longitude): """ - Convert a WGS84 (latitude, longitude) tuple into a (easting, northing) tuple + Convert a WGS84 (latitude, longitude) position, returns a (easting, northing) tuple """ - position = convertWGS84toOSGB36(*position) - easting, northing = LatLongToOSGrid(position[0], position[1]) + (new_latitude, new_longitude, _ignore) = convertWGS84toOSGB36(latitude, longitude) + easting, northing = LatLongToOSGrid(new_latitude, new_longitude) return (easting, northing) # Final function to make headings more user-friendly diff --git a/whensmytransport.py b/whensmytransport.py index 543a2f0..97aeac7 100644 --- a/whensmytransport.py +++ b/whensmytransport.py @@ -176,7 +176,7 @@ def get_tweet_geolocation(self, tweet, user_request): if hasattr(tweet, 'geo') and tweet.geo and tweet.geo.has_key('coordinates'): logging.debug("Detect geolocation on Tweet") position = tweet.geo['coordinates'] - easting, northing = convertWGS84toOSEastingNorthing(position) + easting, northing = convertWGS84toOSEastingNorthing(*position) gridref = gridrefNumToLet(easting, northing) # Grid reference provides us an easy way with checking to see if in the UK - it returns blank string if not in UK bounds if not gridref: