def toUtm(self, Utm=Utm): '''Convert this MGRS grid reference to a UTM coordinate. @keyword Utm: Optional (sub-)class to return the UTM coordinate (L{Utm}) or C{None}. @return: The UTM coordinate (L{Utm}) or a L{UtmUps4Tuple}C{(zone, hemipole, easting, northing)} if B{C{Utm}} is C{None}. @example: >>> m = Mgrs('31U', 'DQ', 448251, 11932) >>> u = m.toUtm() # 31 N 448251 5411932 ''' # get northing of the band bottom, extended to # include entirety of bottom-most 100 km square n = toUtm8(self._bandLat, 0, datum=self._datum).northing nb = int(n / _100km) * _100km e, n = self._en100k2m() # 100 km grid square row letters repeat every 2,000 km north; # add enough 2,000 km blocks to get into required band e += self._easting n += self._northing while n < nb: n += _2000km h = _hemi(self.bandLatitude) # if self._band < 'N' if Utm is None: r = UtmUps4Tuple(self.zone, h, e, n) else: r = Utm(self.zone, h, e, n, band=self.band, datum=self.datum) return self._xnamed(r)
def toUtmUps8(latlon, lon=None, datum=None, Utm=Utm, Ups=Ups, pole='', name=''): '''Convert a lat-/longitude point to a UTM or UPS coordinate. @param latlon: Latitude (C{degrees}) or an (ellipsoidal) geodetic C{LatLon} point. @keyword lon: Optional longitude (C{degrees}) or C{None}. @keyword datum: Optional datum to use this UTM coordinate, overriding I{latlon}'s datum (C{Datum}). @keyword Utm: Optional (sub-)class to return the UTM coordinate (L{Utm}) or C{None}. @keyword Ups: Optional (sub-)class to return the UPS coordinate (L{Ups}) or C{None}. @keyword pole: Optional top/center of UPS (stereographic) projection (C{str}, C{'N[orth]'} or C{'S[outh]'}). @keyword name: Optional name (C{str}). @return: The UTM or UPS coordinate (L{Utm} respectively L{Ups}) or an 8-tuple (C{zone, hemisphere/pole, easting, northing, Band, datum, convergence, scale}) if I{Utm} respectively I{Ups} is C{None} or I{cmoff} is C{False} as (C{int, 'N'|'S', meter, meter, str, degrees, scalar}) where C{zone} is C{1..60} for UTM or C{0} for UPS and C{Band} is C{""} or C{'C'|'D'..'W'|'X'} for UTM or C{'A'|'B'|'Y'|'Z'} for UPS. @raise RangeError: If I{lat} outside the valid UTM or UPS bands or if I{lat} or I{lon} outside the valid range and I{rangerrrors} set to C{True}. @raise TypeError: If I{latlon} is not ellipsoidal or I{lon} value is missing. @raise UTMUPSError: UTM or UPS validation failed. @raise ValueError: Invalid I{lat} or I{lon}. @see: Functions L{toUtm8} and L{toUps8}. ''' lat, lon, d, name = _to4lldn(latlon, lon, datum, name) z, B, p, lat, lon = utmupsZoneBand5(lat, lon) if z == _UPS_ZONE: u = toUps8(lat, lon, datum=d, Ups=Ups, pole=pole or p, falsed=True, name=name) else: u = toUtm8(lat, lon, datum=d, Utm=Utm, cmoff=True, name=name) return u
def toUtm(self): '''Convert this C{LatLon} point to a UTM coordinate. @return: The UTM coordinate (L{Utm}). @see: Function L{toUtm8}. ''' if self._utm is None: from utm import toUtm8, Utm # PYCHOK recursive import self._utm = toUtm8(self, datum=self.datum, Utm=Utm) return self._utm
def toUtm(self, zone, **unused): '''Convert this UPS coordinate to a UTM coordinate. @param zone: The UTM zone (C{int}). @return: The UTM coordinate (L{Utm}). ''' u = self._utm if u is None or u.zone != zone: from utm import toUtm8 # PYCHOK recursive import ll = self.toLatLon(LatLon=None, unfalse=True) self._utm = toUtm8(ll, name=self.name, zone=zone) return self._utm
def toUtm(latlon, lon=None, datum=None, Utm=_UTM, cmoff=True, name=''): '''DEPRECATED, use function L{toUtm8}. @return: The UTM coordinate (B{C{Utm}}) or a 6-tuple C{(zone, easting, northing, band, convergence, scale)} if B{C{Utm}} is C{None} or B{C{cmoff}} is C{False}. ''' from utm import toUtm8, Utm as _Utm U = _Utm if Utm is _UTM else Utm r = toUtm8(latlon, lon=lon, datum=datum, Utm=U, name=name, falsed=cmoff) if isinstance(r, tuple): # UtmUps8Tuple # no hemisphere/pole and datum r = r.zone, r.easting, r.northing, r.band, r.convergence, r.scale return r
def toUtm(self, zone, falsed=True, **unused): '''Convert this UPS coordinate to a UTM coordinate. @param zone: The UTM zone (C{int}). @keyword falsed: False both easting and northing (C{bool}). @return: The UTM coordinate (L{Utm}). ''' u = self._utm if u is None or u.zone != zone or falsed != u.falsed: from utm import toUtm8, Utm # PYCHOK recursive import ll = self.toLatLon(LatLon=None, unfalse=True) self._utm = toUtm8(ll, Utm=Utm, falsed=falsed, name=self.name, zone=zone) return self._utm
def toUtmUps8(latlon, lon=None, datum=None, falsed=True, Utm=Utm, Ups=Ups, pole='', name='', **cmoff): '''Convert a lat-/longitude point to a UTM or UPS coordinate. @param latlon: Latitude (C{degrees}) or an (ellipsoidal) geodetic C{LatLon} point. @keyword lon: Optional longitude (C{degrees}) or C{None}. @keyword datum: Optional datum to use this UTM coordinate, overriding B{C{latlon}}'s datum (C{Datum}). @keyword falsed: False both easting and northing (C{bool}). @keyword Utm: Optional (sub-)class to return the UTM coordinate (L{Utm}) or C{None}. @keyword Ups: Optional (sub-)class to return the UPS coordinate (L{Ups}) or C{None}. @keyword pole: Optional top/center of UPS (stereographic) projection (C{str}, C{'N[orth]'} or C{'S[outh]'}). @keyword name: Optional name (C{str}). @keyword cmoff: DEPRECATED, use B{C{falsed}}. Offset longitude from zone's central meridian, for UTM only (C{bool}). @return: The UTM or UPS coordinate (B{C{Utm}} respectively B{C{Ups}}) or a L{UtmUps8Tuple}C{(zone, hemipole, easting, northing, band, datum, convergence, scale)} if B{C{Utm}} respectively B{C{Ups}} is C{None} or B{C{cmoff}} is C{False}. @raise RangeError: If B{C{lat}} outside the valid UTM or UPS bands or if B{C{lat}} or B{C{lon}} outside the valid range and L{rangerrors} set to C{True}. @raise TypeError: If B{C{latlon}} is not ellipsoidal or B{C{lon}} value is missing. @raise UTMUPSError: UTM or UPS validation failed. @raise ValueError: Invalid B{C{lat}} or B{C{lon}}. @see: Functions L{toUtm8} and L{toUps8}. ''' lat, lon, d, name = _to4lldn(latlon, lon, datum, name) z, B, p, lat, lon = utmupsZoneBand5(lat, lon) f = falsed and cmoff.get('cmoff', True) if z == _UPS_ZONE: u = toUps8(lat, lon, datum=d, falsed=f, Ups=Ups, pole=pole or p, name=name) else: u = toUtm8(lat, lon, datum=d, falsed=f, Utm=Utm, name=name) return u