Exemplo n.º 1
0
def degDMS(deg, prec=6, s_D=S_DEG, s_M=S_MIN, s_S=S_SEC, neg='-', pos=''):
    '''Convert degrees to a string in degrees, minutes I{or} seconds.

       @param deg: Value in degrees (C{scalar}).
       @keyword prec: Optional number of decimal digits (0..9 or
                      C{None} for default).  Trailing zero decimals
                      are stripped for B{C{prec}} values of 1 and
                      above, but kept for negative B{C{prec}}.
       @keyword s_D: Symbol for degrees (C{str}).
       @keyword s_M: Symbol for minutes (C{str}) or C{""}.
       @keyword s_S: Symbol for seconds (C{str}) or C{""}.
       @keyword neg: Optional sign for negative ('-').
       @keyword pos: Optional sign for positive ('').

       @return: I{Either} degrees, minutes I{or} seconds (C{str}).
    '''
    d, s = abs(deg), s_D
    if d < 1:
        if s_M:
            d *= 60
            if d < 1 and s_S:
                d *= 60
                s = s_S
            else:
                s = s_M
        elif s_S:
            d *= 3600
            s = s_S

    n = neg if deg < 0 else pos
    z = int(prec)
    t = '%s%.*f' % (n, abs(z), d)
    if z > 1:
        t = fStrzs(t)
    return t + s
Exemplo n.º 2
0
def _toDMS(deg, form, prec, sep, ddd, suff):  # MCCABE 14
    '''(INTERNAL) Convert degrees to C{str}, with/-out sign and/or suffix.
    '''
    try:
        d = abs(float(deg))
    except ValueError:
        raise ValueError('%s invalid: %r' % ('deg', deg))

    form = form.lower()
    sign = form[:1]
    if sign in '-+':
        form = form[1:]
    else:
        sign = ''

    if prec is None:
        z = p = _F_prec.get(form, 6)
    else:
        z = int(prec)
        p = abs(z)
    w = p + (1 if p else 0)

    if form in (F_DEG, F_MIN, F_SEC):
        s_deg = s_min = s_sec = ''  # no symbols
    else:
        s_deg, s_min, s_sec = S_DEG, S_MIN, S_SEC

    if form in (F_D, F_DEG, 'degrees'):  # deg°, degrees
        t = '%0*.*f' % (ddd+w,p,d)
        s = s_deg

    elif form in (F_RAD, 'radians'):
        t = '%.*f' % (p,radians(d))
        s = S_RAD

    elif form in (F_DM, F_MIN, 'deg+min'):
        d, m = divmod(d * 60, 60)
        t = "%0*d%s%s%0*.*f" % (ddd,int(d),s_deg, sep, w+2,p,m)
        s = s_min

    else:  # F_DMS, F_SEC, 'deg+min+sec'
        d, s = divmod(d * 3600, 3600)
        m, s = divmod(s, 60)
        t = "%0*d%s%s%02d%s%s%0*.*f" % (ddd,int(d),s_deg, sep,
                                            int(m),s_min, sep,
                                          w+2,p,s)
        s = s_sec

    if z > 1:
        t = fStrzs(t)

    if sign:
        if deg < 0:
            t = '-' + t
        elif deg > 0 and sign == '+':
            t = '+' + t
    elif suff:
        s += sep + suff
    return t + s
Exemplo n.º 3
0
    def toStr(self):  # PYCHOK expected
        '''Return this reference frame as a text string.

           @return: This L{RefFrame}'s attributes (C{str}).
        '''
        e = self.ellipsoid
        t = ('name=%r'               % (self.name,),
             'epoch=%s'              % (fStrzs('%.3f' % (self.epoch,)),),
             'ellipsoid=%s(name=%r)' % (classname(e), e.name))
        return ', '.join(t)