def toStr(self, prec=10, sep=_SPACE_): # PYCHOK expected '''Return a string representation of this OSGR coordinate. Note that OSGR coordinates are truncated, not rounded (unlike UTM grid references). @kwarg prec: Optional number of digits (C{int}). @kwarg sep: Optional C{join} separator (C{str}) or C{None} to return an unjoined C{tuple} of C{str}s. @return: This OSGR as C{"EN easting northing"} or as C{"easting,northing"} if B{C{prec}} is non-positive (C{str}). @raise ValueError: Invalid B{C{prec}}. @example: >>> r = Osgr(651409, 313177) >>> str(r) # TG 5140 1317 >>> r.toStr(prec=0) # 651409,313177 ''' def _i2c(i): if i > 7: i += 1 return chr(_ord_A + i) e, n, s = self._easting, self._northing, _COMMA_ if prec > 0: E, e = divmod(e, _100km) N, n = divmod(n, _100km) E, N = int(E), int(N) if 0 > E or E > 6 or \ 0 > N or N > 12: return NN N = 19 - N EN = _i2c( N - (N % 5) + (E + 10) // 5) + \ _i2c((N * 5) % 25 + (E % 5)) t = enstr2(e, n, prec, EN) s = sep elif -6 < prec < 0: w = 6 + 1 - prec t = ['%0*.*f' % (w, -prec, t) for t in (e, n)] else: t = ['%06d' % int(t) for t in (e, n)] return tuple(t) if s is None else s.join(t)
def toStr(self, prec=10, sep=' '): # PYCHOK expected '''Return a string representation of this MGRS grid reference. Note that MGRS grid references are truncated, not rounded (unlike UTM coordinates). @kwarg prec: Optional number of digits (C{int}), 4:km, 10:m. @kwarg sep: Optional separator to join (C{str}). @return: This Mgrs as "00B EN easting northing" (C{str}). @raise ValueError: Invalid B{C{prec}}. @example: >>> m = Mgrs(31, 'DQ', 48251, 11932, band='U') >>> m.toStr() # '31U DQ 48251 11932' ''' t = enstr2(self._easting, self._northing, prec, '%02d%s' % (self._zone, self._band), self._en100k) return sep.join(t)
def enStr2(easting, northing, prec, *extras): # PYCHOK no cover '''DEPRECATED, use function L{enstr2}. ''' from pygeodesy.streprs import enstr2 return enstr2(easting, northing, prec, *extras)