Ejemplo n.º 1
0
def _rsT(T):
    '''(INTERNAL) Helper for C{_RD}, C{_RF} and C{_RJ}.
    '''
    s = map2(sqrt, T[1:])
    r = fdot(s[:3], s[1], s[2], s[0])
    T[:] = [(t + r) * 0.25 for t in T]
    return r, s, T
Ejemplo n.º 2
0
 def sizes(self):
     '''Get the lat- and longitudinal size of this cell as
        a L{LatLon2Tuple}C{(lat, lon)} with the latitudinal
        height and longitudinal width in (C{meter}).
     '''
     n = min(len(_Sizes) - 1, self.precision or 1)
     return LatLon2Tuple(*map2(float, _Sizes[n][:2]))
Ejemplo n.º 3
0
def unStr(name, *args, **kwds):
    '''Return the string representation of an invokation.

       @param name: Function, method or class name (C{str}).
       @param args: Optional positional arguments.
       @keyword kwds: Optional keyword arguments.

       @return: Representation (C{str}).
    '''
    t = tuple('%s=%s' % t for t in sorted(kwds.items()))
    if args:
        t = map2(str, args) + t
    return '%s(%s)' % (name, ', '.join(t))
Ejemplo n.º 4
0
    def __init__(self, AB, x, y):
        '''(INTERNAL) New Alpha or Beta Krüger series

           @param AB: Krüger Alpha or Beta series coefficients (4-,
                      6- or 8-tuple).
           @param x: Eta angle (C{radians}).
           @param y: Ksi angle (C{radians}).
        '''
        n, j2 = len2(range(2, len(AB) * 2 + 1, 2))

        self._ab = AB
        self._pq = map2(mul, j2, self._ab)
        #       assert len(self._ab) == len(self._pq) == n

        x2 = map2(mul, j2, (x, ) * n)
        self._chx = map2(cosh, x2)
        self._shx = map2(sinh, x2)
        #       assert len(x2) == len(self._chx) == len(self._shx) == n

        y2 = map2(mul, j2, (y, ) * n)
        self._cy = map2(cos, y2)
        self._sy = map2(sin, y2)
Ejemplo n.º 5
0
    def __init__(self, AB, x, y):
        '''(INTERNAL) New Alpha or Beta Krüger series

           @param AB: 6th-order Krüger Alpha or Beta series
                      coefficients (7-tuple, 1-origin).
           @param x: Eta angle (radians).
           @param y: Ksi angle (radians).
        '''
        n, j2 = len2(range(2, len(AB) * 2, 2))

        self._ab = AB[1:]  # 0-origin
        self._pq = map2(mul, j2, self._ab)
        #       assert len(self._ab) == len(self._pq) == n

        x2 = map2(mul, j2, (x, ) * n)
        self._chx = map2(cosh, x2)
        self._shx = map2(sinh, x2)
        #       assert len(x2) == len(self._chx) == len(self._shx) == n

        y2 = map2(mul, j2, (y, ) * n)
        self._cy = map2(cos, y2)
        self._sy = map2(sin, y2)
Ejemplo n.º 6
0
def encode(lat, lon, precision=None):
    '''Encode a lat-/longitude as a geohash, either to the specified
       or if not given, an automatically evaluated precision.

       @param lat: Latitude (C{degrees}).
       @param lon: Longitude (C{degrees}).
       @keyword precision: Optional, desired geohash length (C{int}).

       @return: The geohash (C{str}).

       @raise ValueError: Invalid I{lat}, I{lon} or I{precision}.

       @example:

       >>> geohash.encode(52.205, 0.119,   7)  # 'u120fxw'
       >>> geohash.encode(52.205, 0.119,  12)  # 'u120fxwshvkg'
       >>> geohash.encode(52.205, 0.1188, 12)  # 'u120fxws0jre'
       >>> geohash.encode(52.205, 0.1188)      # 'u120fxw'
       >>> geohash.encode(     0, 0)           # 's00000000000'
    '''
    lat, lon = _2fll(lat, lon)

    if not precision:
        # Infer precision by refining geohash until
        # it matches precision of supplied lat/lon.
        for prec in range(1, 13):
            gh = encode(lat, lon, prec)
            ll = map2(float, decode(gh))
            if abs(lat - ll[0]) < EPS and \
               abs(lon - ll[1]) < EPS:
                return gh
        prec = 12  # maximum
    else:
        try:
            prec = int(precision)
            if not 0 < prec < 13:
                raise ValueError
        except ValueError:
            raise ValueError('%s invalid: %r' % ('precision', precision))

    latS, latN = -90, 90
    lonW, lonE = -180, 180

    b = i = 0
    e, gh = True, []

    while len(gh) < prec:
        i += i
        if e:  # bisect longitude
            m = favg(lonE, lonW)
            if lon < m:
                lonE = m
            else:
                lonW = m
                i += 1
        else:  # bisect latitude
            m = favg(latN, latS)
            if lat < m:
                latN = m
            else:
                latS = m
                i += 1
        e = not e

        b += 1
        if b == 5:
            # 5 bits gives a character:
            # append it and start over
            gh.append(_GeohashBase32[i])
            b = i = 0

    return ''.join(gh)
Ejemplo n.º 7
0
 def sizes(self):
     '''Get the lat- and longitudinal size of this cell as
        a 2-tuple (latHeight, lonWidth) in meter.
     '''
     n = min(len(_Sizes) - 1, len(self) or 1)
     return map2(float, _Sizes[n][:2])
Ejemplo n.º 8
0
 def ab(self):
     '''Get the lat- and longitude of (the approximate center of)
        this geohash as a 2-tuple (lat, lon) in radians.
     '''
     return map2(radians, self.latlon)