当前位置: 首页>>代码示例>>Python>>正文


Python exc.GeocoderServiceError方法代码示例

本文整理汇总了Python中geopy.exc.GeocoderServiceError方法的典型用法代码示例。如果您正苦于以下问题:Python exc.GeocoderServiceError方法的具体用法?Python exc.GeocoderServiceError怎么用?Python exc.GeocoderServiceError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在geopy.exc的用法示例。


在下文中一共展示了exc.GeocoderServiceError方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_geocoordinates

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def get_geocoordinates(geolocator, listing_object):
    address, city, state, zip_code = construct_full_address(listing_object)
    address_string_combinations = [
        '%s %s %s %s' % (address, city, state, zip_code),
        '%s %s %s' % (address, city, state),
        '%s %s' % (address, zip_code)
    ]
    location = None
    for address_string_combination in address_string_combinations:
        try:
            location = geolocator.geocode(address_string_combination)
        except (GeocoderTimedOut, GeocoderServiceError, GeocoderUnavailable):
            time.sleep(10)
            try:
                location = geolocator.geocode(address_string_combination)
            except (
                    GeocoderTimedOut, GeocoderServiceError,
                    GeocoderUnavailable):
                return None, None
        if location:
            return location.latitude, location.longitude
        else:
            continue
    if not location:
        return None, None 
开发者ID:bgirer,项目名称:rets-django,代码行数:27,代码来源:update_listings.py

示例2: retrying_set_location

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def retrying_set_location(location_name):
    """
    Continue trying to get co-ords from Google Location until we have them
    :param location_name: string to pass to Location API
    :return: None
    """

    while True:
        try:
            set_location(location_name)
            return
        except (GeocoderTimedOut, GeocoderServiceError), e:
            debug(
                'retrying_set_location: geocoder exception ({}), retrying'.format(
                    str(e)))
        time.sleep(1.25) 
开发者ID:rubenmak,项目名称:PokemonGo-SlackBot,代码行数:18,代码来源:pokehomey.py

示例3: geocode

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def geocode(self, address):
        if not isinstance(address, basestring) \
                and not isinstance(address, dict):
            err_msg = u"address should either be of type: %s, or of type %s." \
                      % (basestring, dict)
            raise TypeError(err_msg)

        try:
            geolocation = self._geocoder.geocode(address)

            if not geolocation:
                err_msg = u"Couldn't resolve the following address: '%s'" \
                          % address
                raise GeolocationFailure(err_msg)
        except (exc.GeocoderQuotaExceeded,
                exc.GeocoderUnavailable,
                exc.GeocoderTimedOut) as e:
            raise TemporaryError(u'Geolocator error: %s' % e)
        except exc.GeocoderServiceError as e:
            raise GeolocationError(u'Geolocator error: %s' % e)

        return geolocation 
开发者ID:pyjobs,项目名称:web,代码行数:24,代码来源:geolocation.py

示例4: retrying_set_location

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def retrying_set_location(location_name):
    """
    Continue trying to get co-ords from Google Location until we have them
    :param location_name: string to pass to Location API
    :return: None
    """

    while True:
        try:
            set_location(location_name)
            return
        except (GeocoderTimedOut, GeocoderServiceError), e:
            debug(
                'retrying_set_location: geocoder exception ({}), retrying'.format(str(e)))
        time.sleep(1.25) 
开发者ID:Girish-Raguvir,项目名称:PokemonGo-RedStreak,代码行数:17,代码来源:main.py

示例5: geocode

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def geocode(self, query, exactly_one=True, timeout=None):
        """
        Geocode a location query.

        :param string query: The address or query you wish to geocode.

        :param bool exactly_one: Return one result or a list of results, if
            available.

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.
        """
        params = {'text': query, 'f': 'json'}
        if exactly_one is True:
            params['maxLocations'] = 1
        url = "?".join((self.api, urlencode(params)))
        logger.debug("%s.geocode: %s", self.__class__.__name__, url)
        response = self._call_geocoder(url, timeout=timeout)

        # Handle any errors; recursing in the case of an expired token.
        if 'error' in response:
            if response['error']['code'] == self._TOKEN_EXPIRED:
                self.retry += 1
                self._refresh_authentication_token()
                return self.geocode(
                    query, exactly_one=exactly_one, timeout=timeout
                )
            raise GeocoderServiceError(str(response['error']))

        # Success; convert from the ArcGIS JSON format.
        if not len(response['locations']):
            return None
        geocoded = []
        for resource in response['locations']:
            geometry = resource['feature']['geometry']
            geocoded.append(
                Location(
                    resource['name'], (geometry['y'], geometry['x']), resource
                )
            )
        if exactly_one is True:
            return geocoded[0]
        return geocoded 
开发者ID:Wildog,项目名称:pythonista-toys,代码行数:47,代码来源:arcgis.py

示例6: reverse

# 需要导入模块: from geopy import exc [as 别名]
# 或者: from geopy.exc import GeocoderServiceError [as 别名]
def reverse(self, query, exactly_one=True, timeout=None, # pylint: disable=R0913,W0221
                distance=None, wkid=DEFAULT_WKID):
        """
        Given a point, find an address.

        :param query: The coordinates for which you wish to obtain the
            closest human-readable addresses.
        :type query: :class:`geopy.point.Point`, list or tuple of (latitude,
            longitude), or string as "%(latitude)s, %(longitude)s".

        :param bool exactly_one: Return one result, or a list?

        :param int timeout: Time, in seconds, to wait for the geocoding service
            to respond before raising a :class:`geopy.exc.GeocoderTimedOut`
            exception. Set this only if you wish to override, on this call
            only, the value set during the geocoder's initialization.

        :param int distance: Distance from the query location, in meters,
            within which to search. ArcGIS has a default of 100 meters, if not
            specified.

        :param string wkid: WKID to use for both input and output coordinates.
        """
        # ArcGIS is lon,lat; maintain lat,lon convention of geopy
        point = self._coerce_point_to_string(query).split(",")
        if wkid != DEFAULT_WKID:
            location = {"x": point[1], "y": point[0], "spatialReference": wkid}
        else:
            location = ",".join((point[1], point[0]))
        params = {'location': location, 'f': 'json', 'outSR': wkid}
        if distance is not None:
            params['distance'] = distance
        url = "?".join((self.reverse_api, urlencode(params)))
        logger.debug("%s.reverse: %s", self.__class__.__name__, url)
        response = self._call_geocoder(url, timeout=timeout)
        if not len(response):
            return None
        if 'error' in response:
            if response['error']['code'] == self._TOKEN_EXPIRED:
                self.retry += 1
                self._refresh_authentication_token()
                return self.reverse(query, exactly_one=exactly_one,
                                    timeout=timeout, distance=distance,
                                    wkid=wkid)
            raise GeocoderServiceError(str(response['error']))
        address = (
            "%(Address)s, %(City)s, %(Region)s %(Postal)s,"
            " %(CountryCode)s" % response['address']
        )
        return Location(
            address,
            (response['location']['y'], response['location']['x']),
            response['address']
        ) 
开发者ID:Wildog,项目名称:pythonista-toys,代码行数:56,代码来源:arcgis.py


注:本文中的geopy.exc.GeocoderServiceError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。