# - - - L a t L o n . _ _ s t r _ _
def __str__ ( self ):
"""Return self as a string.
"""
Values returned here should look like this example:
[03d 14m 32s N Lat 118d 32m 04s W Lon]
Because self.lon is in the range [0,
2π], we have to treat values in the range
[π, 2π) differently: values in that range
are subtracted from 2π, and those will be shown as
west longitude. Similarly, negative latitudes are shown
as positive south latitude. The degrees()
function from Python's math module
converts radians to degrees.
#-- 1 --
if self.lon >= pi:
e_w = "W"
lonDeg = degrees ( TWO_PI - self.lon )
else:
e_w = "E"
lonDeg = degrees ( self.lon )
#-- 2 --
if self.lat < 0:
n_s = "S"
latDeg = degrees ( - self.lat )
else:
n_s = "N"
latDeg = degrees ( self.lat )
Next we get lists of formatted values in the degrees-minutes-seconds system. The rest is just simple formatting.
#-- 3 --
# [ latList := three formatted values of latDeg in
# degrees/minutes/seconds
# lonList := three formatted values of lonDeg similarly ]
latList = dmsUnits.format ( dmsUnits.singleToMix(latDeg), 1 )
lonList = dmsUnits.format ( dmsUnits.singleToMix(lonDeg), 1 )
#-- 4 --
return ( '[%sd %s\' %s" %s Lat %sd %s\' %s" %s Lon]' %
(latList[0], latList[1], latList[2], n_s,
lonList[0], lonList[1], lonList[2], e_w) )