Skip to content

Commit

Permalink
Use latitude & longitude as separate params for consistency, rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
qwghlm committed Mar 2, 2012
1 parent aa9dce1 commit c2568a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions lib/geo.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion whensmytransport.py
Expand Up @@ -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:
Expand Down

0 comments on commit c2568a4

Please sign in to comment.