def __new__(cls, cll, precision=3, name=NN): '''New L{Georef} from an other L{Georef} instance or georef C{str} or from a C{LatLon} instance or lat-/longitude C{str}. @arg cll: Cell or location (L{Georef} or C{str}, C{LatLon} or C{str}). @kwarg precision: Optional, the desired georef resolution and length (C{int} 0..11), see function L{wgrs.encode} for more details. @kwarg name: Optional name (C{str}). @return: New L{Georef}. @raise RangeError: Invalid B{C{cll}} lat- or longitude. @raise TypeError: Invalid B{C{cll}}. @raise WGRSError: INValid or non-alphanumeric B{C{cll}}. ''' h = None if isinstance(cll, Georef): g, p = _2geostr2(str(cll)) self = Str.__new__(cls, g) self._latlon = LatLon2Tuple(*cll._latlon) self._precision = p # cll._precision if cll._name: self._name = cll._name elif isstr(cll): if ',' in cll: lat, lon, h = _2fllh(*parse3llh(cll, height=None)) g = encode(lat, lon, precision=precision, height=h) # PYCHOK false self = Str.__new__(cls, g) self._latlon = LatLon2Tuple(lat, lon) else: self = Str.__new__(cls, cll.upper()) self._decode() else: # assume LatLon try: lat, lon, h = _2fllh(cll.lat, cll.lon) h = getattr(cll, _height_, h) except AttributeError: raise _xStrError(Georef, cll=cll) # Error=WGRSError g = encode(lat, lon, precision=precision, height=h) # PYCHOK false self = Str.__new__(cls, g) self._latlon = LatLon2Tuple(lat, lon) if h not in (None, MISSING): self._height = Height(h) if self._precision is None: self._precision = _2Precision(precision) if name: self.name = name return self
def __new__(cls, cll, precision=1, name=NN): '''New L{Garef} from an other L{Garef} instance or garef C{str} or from a C{LatLon} instance or lat-/longitude C{str}. @arg cll: Cell or location (L{Garef} or C{str}, C{LatLon} or C{str}). @kwarg precision: Optional, the desired garef resolution and length (C{int} 0..2), see function L{gars.encode} for more details. @kwarg name: Optional name (C{str}). @return: New L{Garef}. @raise RangeError: Invalid B{C{cll}} lat- or longitude. @raise TypeError: Invalid B{C{cll}}. @raise GARSError: INValid or non-alphanumeric B{C{cll}}. ''' if isinstance(cll, Garef): g, p = _2garstr2(str(cll)) self = Str.__new__(cls, g) self._latlon = LatLon2Tuple(*cll._latlon) self._name = cll._name self._precision = p # cll._precision elif isstr(cll): if ',' in cll: lat, lon = _2fll(*parse3llh(cll)) cll = encode(lat, lon, precision=precision) # PYCHOK false self = Str.__new__(cls, cll) self._latlon = LatLon2Tuple(lat, lon) else: self = Str.__new__(cls, cll.upper()) self._decode() else: # assume LatLon try: lat, lon = _2fll(cll.lat, cll.lon) except AttributeError: raise _xStrError(Garef, cll=cll) # Error=GARSError cll = encode(lat, lon, precision=precision) # PYCHOK false self = Str.__new__(cls, cll) self._latlon = LatLon2Tuple(lat, lon) if self._precision is None: self._precision = _2Precision(precision) if name: self.name = name return self
def __new__(cls, cll, precision=None, name=NN): '''New L{Geohash} from an other L{Geohash} instance or C{str} or from a C{LatLon} instance or C{str}. @arg cll: Cell or location (L{Geohash} or C{str}, C{LatLon} or C{str}). @kwarg precision: Optional, the desired geohash length (C{int} 1..12), see function L{geohash.encode} for some examples. @kwarg name: Optional name (C{str}). @return: New L{Geohash}. @raise TypeError: Invalid B{C{cll}}. @raise GeohashError: INValid or non-alphanumeric B{C{cll}}. ''' if isinstance(cll, Geohash): gh = _2geostr(str(cll)) self = Str.__new__(cls, gh) elif isstr(cll): if ',' in cll: lat, lon = _2fll(*parse3llh(cll)) gh = encode(lat, lon, precision=precision) self = Str.__new__(cls, gh) self._latlon = lat, lon else: gh = _2geostr(cll) self = Str.__new__(cls, gh) else: # assume LatLon try: lat, lon = _2fll(cll.lat, cll.lon) except AttributeError: raise _xStrError(Geohash, cll=cll) # Error=GeohashError gh = encode(lat, lon, precision=precision) self = Str.__new__(cls, gh) self._latlon = lat, lon if name: self.name = name return self