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]))
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
def __init__(self, knots, weight=None, name=''): '''New L{HeightLSQBiSpline} interpolator. @param knots: The points with known height (C{LatLon}s). @keyword weight: Optional weight or weights for each B{C{knot}} (C{scalar} or C{scalar}s). @keyword name: Optional height interpolator name (C{str}). @raise HeightError: Insufficient number of B{C{knots}} or B{C{weight}}s or invalid B{C{knot}} or B{C{weight}}. @raise ImportError: Package C{numpy} or C{scipy} not found or not installed. @raise SciPyError: A C{LSQSphereBivariateSpline} issue. @raise SciPyWarning: A C{LSQSphereBivariateSpline} warning as exception. ''' np, spi = self._NumSciPy() xs, ys, hs = self._xyhs3(knots) n = len(hs) w = weight if isscalar(w): w = float(w) if w <= 0: raise HeightError('%s invalid: %.6f' % ('weight', w)) w = [w] * n elif w is not None: m, w = len2(w) if m != n: raise HeightError('%s invalid: %s, not %s' % ('number of weights', m, n)) w = map2(float, w) m = min(w) if m <= 0: raise HeightError('%s[%s] invalid: %.6f' % ('weight', w.find(m), m)) try: T = 1.0e-4 # like SciPy example ps = np.array(_ordedup(xs, T, PI2 - T)) ts = np.array(_ordedup(ys, T, PI - T)) self._ev = spi.LSQSphereBivariateSpline(ys, xs, hs, ts, ps, eps=EPS, w=w).ev except Exception as x: raise _SciPyIssue(x) if name: self.name = name
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))
def __init__(self, AB, x, y): '''(INTERNAL) New Alpha or Beta Krüger series @param AB: Krüger Alpha or Beta series coefficients (C{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)
def encode(lat, lon, precision=None): '''Encode a lat-/longitude as a C{geohash}, either to the specified precision or if not provided, to an automatically evaluated precision. @param lat: Latitude (C{degrees}). @param lon: Longitude (C{degrees}). @keyword precision: Optional, the desired geohash length (C{int} 1..12). @return: The C{geohash} (C{str}). @raise GeohashError: Invalid B{C{lat}}, B{C{lon}} or B{C{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 precision: try: p = int(precision) if not 0 < p <= _MaxPrec: raise ValueError except (TypeError, ValueError): raise GeohashError('%s invalid: %r' % ('precision', precision)) else: # Infer precision by refining geohash until # it matches precision of supplied lat/lon. for p in range(1, _MaxPrec + 1): gh = encode(lat, lon, p) ll = map2(float, decode(gh)) if abs(lat - ll[0]) < EPS and \ abs(lon - ll[1]) < EPS: return gh p = _MaxPrec latS, latN = -90, 90 lonW, lonE = -180, 180 b = i = 0 e, gh = True, [] while len(gh) < p: 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)
def ab(self): '''Get the lat- and longitude of (the approximate center of) this geohash as a 2-tuple (lat, lon) in C{radians}. ''' return map2(radians, self.latlon)