Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _hGeoid(self, lat, lon):
out = self.outside(lat, lon)
if out:
lli = fstr((lat, lon), strepr=repr)
raise RangeError('lli', lli, txt='%s on %s' % (_outside_, out))
return float(self._ev(*self._ll2g2(lat, lon)))
def toStr(self, prec=6, sep=_SPACE_, m=_m_): # PYCHOK expected
'''Return a string representation of this L{Css} position.
@kwarg prec: Optional number of decimal, unstripped (C{int}).
@kwarg sep: Optional separator to join (C{str}) or C{None}
to return an unjoined C{tuple} of C{str}s.
@kwarg m: Optional height units, default C{meter} (C{str}).
@return: This position as C{"easting nothing"} C{str} in
C{meter} plus C{" height"} and C{'m'} if heigth
is non-zero (C{str}).
'''
t = (fstr(self.easting, prec=prec),
fstr(self.northing, prec=prec))
if self.height: # abs(self.height) > EPS
t += ('%+.2f%s' % (self.height, m)),
return t if sep is None else sep.join(t)
@example:
>>> geohash.decode('u120fxw') # '52.205', '0.1188'
>>> geohash.decode('sunny') # '23.708', '42.473' Saudi Arabia
>>> geohash.decode('fur') # '69.6', '-45.7' Greenland
>>> geohash.decode('reef') # '-24.87', '162.95' Coral Sea
>>> geohash.decode('geek') # '65.48', '-17.75' Iceland
'''
b = bounds(geohash)
lat, lon = _2center(b)
# round to near centre without excessive precision
# ⌊2-log10(Δ°)⌋ decimal places, strip trailing zeros
return (fstr(lat, prec=int(2 - log10(b.latN - b.latS))),
fstr(lon, prec=int(2 - log10(b.lonE - b.lonW)))) # strings
print('\n%s\n' % (g.toStr(),))
print('%r\n' % (g.pgm,))
# :
# The height of the EGM96 geoid at Timbuktu
# echo 16:46:33N 3:00:34W | GeoidEval
# => 28.7068 -0.02e-6 -1.73e-6
# The 1st number is the height of the geoid, the 2nd and
# 3rd are its slopes in northerly and easterly direction
t = 'Timbuktu %s' % (g,)
k = {'egm84-15.pgm': '31.2979',
'egm96-5.pgm': '28.7067',
'egm2008-1.pgm': '28.7880'}.get(g.name.lower(), '28.7880')
ll = parseDMS2('16:46:33N', '3:00:34W', sep=':')
for ll in (ll, (16.776, -3.009),):
try:
h, ll = g.height(*ll), fstr(ll, prec=6)
print('%s.height(%s): %.4F vs %s' % (t, ll, h, k))
except (GeoidError, RangeError) as x:
print(_item_cs(t, str(x)))
elif geoid[-4:].lower() in ('.bin',):
g = GeoidG2012B(geoid, kind=_kind)
print(g.toStr())
else:
raise GeoidError('unknown grid', txt=repr(geoid))
_I = int # PYCHOK unused _I
del _intCs # trash ints cache
def _toStr(self, hemipole, B, cs, prec, sep):
'''(INTERNAL) Return a string representation of this UTM/UPS coordinate.
'''
z = '%02d%s' % (self.zone, (self.band if B else NN)) # PYCHOK band
t = (z, hemipole, fstr(self.easting, prec=prec),
fstr(self.northing, prec=prec))
if cs:
t += (_n_a_ if self.convergence is None else
degDMS(self.convergence, prec=8, pos=_PLUS_),
_n_a_ if self.scale is None else
fstr(self.scale, prec=8))
return t if sep is None else sep.join(t)
@kwarg prec: Optional number of decimal, unstripped (C{int}).
@kwarg sep: Optional separator to join (C{str}) or C{None}
to return an unjoined C{tuple} of C{str}s.
@kwarg m: Optional height units, default C{meter} (C{str}).
@return: This Lcc as "easting nothing" C{str} in C{meter} plus
" height" and 'm' if heigth is non-zero (C{str}).
@example:
>>> lb = Lcc(448251, 5411932.0001)
>>> lb.toStr(4) # 448251.0 5411932.0001
>>> lb.toStr(sep=', ') # 448251, 5411932
'''
t = [fstr(self._easting, prec=prec),
fstr(self._northing, prec=prec)]
if self._height:
t += ['%+.2f%s' % (self._height, m)]
return tuple(t) if sep is None else sep.join(t)
def _called(self, llis, scipy):
# handle __call__
_as, llis = _allis2(llis, Error=GeoidError)
try:
hs = []
for i, lli in enumerate(llis):
hs.append(self._hGeoid(lli.lat, lli.lon))
return _as(hs)
except (GeoidError, RangeError) as x:
# XXX avoid str(LatLon()) degree symbols
t = 'lli' if _as is _ascalar else _item_sq(llis=i)
lli = fstr((lli.lat, lli.lon), strepr=repr)
raise type(x)(t, lli, txt=str(x))
except Exception as x:
if scipy and self.scipy:
raise _SciPyIssue(x)
else:
raise
@raise GeohashError: Invalid or null B{C{geohash}}.
@example:
>>> geohash.decode('u120fxw') # '52.205', '0.1188'
>>> geohash.decode('sunny') # '23.708', '42.473' Saudi Arabia
>>> geohash.decode('fur') # '69.6', '-45.7' Greenland
>>> geohash.decode('reef') # '-24.87', '162.95' Coral Sea
>>> geohash.decode('geek') # '65.48', '-17.75' Iceland
'''
b = bounds(geohash)
lat, lon = _2center(b)
# round to near centre without excessive precision
# ⌊2-log10(Δ°)⌋ decimal places, strip trailing zeros
return (fstr(lat, prec=int(2 - log10(b.latN - b.latS))),
fstr(lon, prec=int(2 - log10(b.lonE - b.lonW)))) # strings
@kwarg prec: Optional number of decimal, unstripped (C{int}).
@kwarg sep: Optional separator to join (C{str}) or C{None}
to return an unjoined C{tuple} of C{str}s.
@kwarg m: Optional height units, default C{meter} (C{str}).
@return: This Lcc as "easting nothing" C{str} in C{meter} plus
" height" and 'm' if heigth is non-zero (C{str}).
@example:
>>> lb = Lcc(448251, 5411932.0001)
>>> lb.toStr(4) # 448251.0 5411932.0001
>>> lb.toStr(sep=', ') # 448251, 5411932
'''
t = [fstr(self._easting, prec=prec),
fstr(self._northing, prec=prec)]
if self._height:
t += ['%+.2f%s' % (self._height, m)]
return tuple(t) if sep is None else sep.join(t)