Esempio n. 1
0
    def __new__(cls, cll, precision=None):
        '''New Geohash from a L{Geohash} instance or str or from
           a I{LatLon} instance or string.

           @param cll: Cell or location (L{Geohash} or str, I{LatLon}
                       or string).
           @keyword precision: Optional, desired geohash length (integer),
                               see function L{geohash.encode} for more
                               details.

           @return: New L{Geohash}.
        '''
        if isinstance(cll, Geohash):
            self = str.__new__(cls, _2geostr('%s' % (cll,)))

        elif isinstance(cll, _Str):
            if ',' in cll:
                lat, lon = _2fll(*parse3llh(cll))
                cll = encode(lat, lon, precision=precision)
                self = str.__new__(cls, cll)
                self._latlon = lat, lon
            else:
                self = str.__new__(cls, _2geostr(cll))

        else:  # assume LatLon
            try:
                lat, lon = _2fll(cll.lat, cll.lon)
            except AttributeError:
                raise TypeError('%s: %r' % (Geohash.__name__, cll))
            cll = encode(lat, lon, precision=precision)
            self = str.__new__(cls, cll)
            self._latlon = lat, lon

        return self
Esempio n. 2
0
    def __new__(cls, cll, precision=3, name=''):
        '''New L{Georef} from an other L{Georef} instance or georef
           C{str} or from a C{LatLon} instance or lat-/longitude C{str}.

           @param cll: Cell or location (L{Georef} or C{str}, C{LatLon}
                       or C{str}).
           @keyword precision: Optional, the desired georef resolution
                               and length (C{int} 0..11), see function
                               L{wgrs.encode} for more details.
           @keyword name: Optional name (C{str}).

           @return: New L{Georef}.

           @raise RangeError: Invalid C{cll} lat- or longitude.

           @raise TypeError: Invalid I{cll}.

           @raise ValueError: INValid or non-alphanumeric I{cll}.
        '''
        if isinstance(cll, Georef):
            g, p = _2geostr2(str(cll))
            self = str.__new__(cls, g)
            self._latlon = cll._latlon
            self._name = cll._name
            self._precision = p  # cll._precision

        elif isinstance(cll, _Strs):
            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 = lat, lon
                self._precision = precision
                if h not in (None, _MISSING):
                    self._height = h
            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 TypeError('%s: %r' % (Georef.__name__, cll))
            g = encode(lat, lon, precision=precision, height=h)  # PYCHOK false
            self = str.__new__(cls, g)
            self._latlon = lat, lon
            self._precision = precision
            if h not in (None, _MISSING):
                self._height = h

        if name:
            self.name = name
        return self
Esempio n. 3
0
    def __new__(cls, cll, precision=1, name=''):
        '''New L{Garef} from an other L{Garef} instance or garef
           C{str} or from a C{LatLon} instance or lat-/longitude C{str}.

           @param cll: Cell or location (L{Garef} or C{str}, C{LatLon}
                       or C{str}).
           @keyword precision: Optional, the desired garef resolution
                               and length (C{int} 0..2), see function
                               L{gars.encode} for more details.
           @keyword 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 ValueError: 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 isinstance(cll, _Strs):
            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)
                self._precision = precision
            else:
                self = str.__new__(cls, cll.upper())
                self._decode()

        else:  # assume LatLon
            try:
                lat, lon = _2fll(cll.lat, cll.lon)
            except AttributeError:
                raise TypeError('%s: %r' % (Garef.__name__, cll))
            cll = encode(lat, lon, precision=precision)  # PYCHOK false
            self = str.__new__(cls, cll)
            self._latlon = LatLon2Tuple(lat, lon)
            self._precision = precision

        if name:
            self.name = name
        return self
Esempio n. 4
0
    def parse(self, strll, height=0, sep=','):
        '''Parse a string representing lat-/longitude point and
           return a C{LatLon}.

           The lat- and longitude must be separated by a sep[arator]
           character.  If height is present it must follow and be
           separated by another sep[arator].  Lat- and longitude
           may be swapped, provided at least one ends with the
           proper compass direction.

           For more details, see functions L{parse3llh} and L{parseDMS}
           in module L{dms}.

           @param strll: Lat, lon [, height] (C{str}).
           @keyword height: Optional , default height (C{meter}).
           @keyword sep: Optional separator (C{str}).

           @return: The point (spherical C{LatLon}).

           @raise ValueError: Invalid I{strll}.
        '''
        return self.classof(*parse3llh(strll, height=height, sep=sep))
Esempio n. 5
0
    def __new__(cls, cll, precision=None, name=''):
        '''New L{Geohash} from an other L{Geohash} instance or C{str}
           or from a C{LatLon} instance or C{str}.

           @param cll: Cell or location (L{Geohash} or C{str}, C{LatLon}
                       or C{str}).
           @keyword precision: Optional, the desired geohash length
                               (C{int} 1..12), see function
                               L{geohash.encode} for examples.
           @keyword name: Optional name (C{str}).

           @return: New L{Geohash}.
        '''
        if isinstance(cll, Geohash):
            gh = _2geostr(str(cll))
            self = str.__new__(cls, gh)

        elif isinstance(cll, _Strs):
            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 TypeError('%s: %r' % (Geohash.__name__, cll))
            gh = encode(lat, lon, precision=precision)
            self = str.__new__(cls, gh)
            self._latlon = lat, lon

        if name:
            self.name = name
        return self
Esempio n. 6
0
    def parse(self, strll, height=0, datum=None, sep=','):
        '''Parse a string representing this I{LatLon} point.

           The lat- and longitude must be separated by a sep[arator]
           character.  If height is present it must follow and be
           separated by another sep[arator].  Lat- and longitude
           may be swapped, provided at least one ends with the
           proper compass direction.

           For more details, see functions L{parse3llh} and L{parseDMS}
           in sub-module L{dms}.

           @param strll: Lat, lon [, height] (string).
           @keyword height: Optional, default height (meter or None).
           @keyword datum: Optional, default datum (L{Datum}).
           @keyword sep: Optional separator (string).

           @return: The point (L{LatLonEllipsoidalBase}).

           @raise ValueError: Invalid I{strll}.
        '''
        a, b, h = parse3llh(strll, height=height, sep=sep)
        return self.classof(a, b, height=h, datum=datum or self.datum)