Ejemplo n.º 1
0
 def utmupsStr(self, B=False):
     '''Get the UTM/UPS zone, band and hemisphere/-pole (C{str}).
     '''
     b = self.band if B else NN
     h = s = self.hemisphere
     if h:
         s = _SPACE_
     return NN(Fmt.zone(self.zone), b, s, h)
Ejemplo n.º 2
0
 def _toStr(self, hemipole, B, cs, prec, sep):
     '''(INTERNAL) Return a string for this ETM/UTM/UPS coordinate.
     '''
     z = NN(Fmt.zone(self.zone), (self.band if B else NN))  # PYCHOK band
     t = (z, hemipole) + _fstrENH2(self, prec, None)[0]
     if cs:
         prec = cs if isint(cs) else 8  # for backward compatibility
         t += (_n_a_ if self.convergence is None else degDMS(
             self.convergence, prec=prec, pos=_PLUS_),
               _n_a_ if self.scale is None else fstr(self.scale, prec=prec))
     return t if sep is None else sep.join(t)
Ejemplo n.º 3
0
    def toStr(self, prec=10, sep=_SPACE_):  # 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}) or C{None}
                       to return an unjoined C{tuple} of C{str}s.

           @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 = NN(Fmt.zone(self._zone), self._band)
        t = enstr2(self._easting, self._northing, prec, t, self._en100k)
        return t if sep is None else sep.join(t)
Ejemplo n.º 4
0
__version__ = '20.11.04'

_MGRS_TILE = 100e3  # PYCHOK block size (C{meter})

_UTM_LAT_MAX = _float(84)  # PYCHOK for export (C{degrees})
_UTM_LAT_MIN = _float(-80)  # PYCHOK for export (C{degrees})

_UPS_LAT_MAX = _UTM_LAT_MAX - _0_5  # PYCHOK includes 30' UTM overlap
_UPS_LAT_MIN = _UTM_LAT_MIN + _0_5  # PYCHOK includes 30' UTM overlap

_UTM_ZONE_MAX = 60  # PYCHOK for export
_UTM_ZONE_MIN = 1  # PYCHOK for export
_UTM_ZONE_OFF_MAX = 60  # PYCHOK max Central meridian offset (C{degrees})

_UPS_ZONE = _UTM_ZONE_MIN - 1  # PYCHOK for export
_UPS_ZONE_STR = Fmt.zone(_UPS_ZONE)  # PYCHOK for export

_UTMUPS_ZONE_INVALID = -4  # PYCHOK for export too
_UTMUPS_ZONE_MAX = _UTM_ZONE_MAX  # PYCHOK for export too, by .units.py
_UTMUPS_ZONE_MIN = _UPS_ZONE  # PYCHOK for export too, by .units.py

# _MAX_PSEUDO_ZONE      = -1
# _MIN_PSEUDO_ZONE      = -4
# _UTMUPS_ZONE_MATCH    = -3
# _UTMUPS_ZONE_STANDARD = -1
# _UTM                  = -2


def _hemi(lat):  # imported by .ups, .utm
    '''Return the hemisphere letter.
Ejemplo n.º 5
0
def utmupsValidate(coord, falsed=False, MGRS=False, Error=UTMUPSError):
    '''Check a UTM or UPS coordinate.

       @arg coord: The UTM or UPS coordinate (L{Utm}, L{Ups} or C{5+Tuple}).
       @kwarg falsed: C{5+Tuple} easting and northing are falsed (C{bool}).
       @kwarg MGRS: Increase easting and northing ranges (C{bool}).
       @kwarg Error: Optional error to raise, overriding the default
                     (L{UTMUPSError}).

       @return: C{None} if validation passed.

       @raise Error: Validation failed.

       @see: Function L{utmupsValidateOK}.
    '''
    def _en(en, lo, hi, ename):  # U, Error
        try:
            if lo <= float(en) <= hi:
                return
        except (TypeError, ValueError):
            pass
        t = _SPACE_(_outside_, U, _range_, _range_(lo, hi))
        raise Error(ename, en, txt=t)

    if isinstance(coord, (Ups, Utm)):
        hemi = coord.hemisphere
        enMM = coord.falsed
    elif isinstance(coord, (UtmUps5Tuple, UtmUps8Tuple)):
        hemi = coord.hemipole
        enMM = falsed
    else:
        raise _IsnotError(Error=Error,
                          coord=coord,
                          *map1(modulename, Utm, Ups, UtmUps5Tuple,
                                UtmUps8Tuple))
    band = coord.band
    zone = coord.zone

    z, B, h = _to3zBhp(zone, band, hemipole=hemi)

    if z == _UPS_ZONE:  # UPS
        import pygeodesy.ups as u  # PYCHOK expected
        U, M = _UPS_, _UpsMinMax
    else:  # UTM
        import pygeodesy.utm as u  # PYCHOK expected
        U, M = _UTM_, _UtmMinMax

    if MGRS:
        U, s = _MGRS_, _MGRS_TILE
    else:
        s = 0

    i = _NS_.find(h)
    if i < 0 or z < _UTMUPS_ZONE_MIN \
             or z > _UTMUPS_ZONE_MAX \
             or B not in u._Bands:
        t = Fmt.PAREN(U, repr(_SPACE_(NN(Fmt.zone(z), B), h)))
        raise Error(coord=t, zone=zone, band=band, hemisphere=hemi)

    if enMM:
        _en(coord.easting, M.eMin[i] - s, M.eMax[i] + s,
            _easting_)  # PYCHOK .eMax .eMin
        _en(coord.northing, M.nMin[i] - s, M.nMax[i] + s,
            _northing_)  # PYCHOK .nMax .nMin