How to use the geopy.geocoders.base.Geocoder function in geopy

To help you get started, we’ve selected a few geopy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github geopy / geopy / test / test_proxy.py View on Github external
try:
    from urllib.request import getproxies
except ImportError:  # py2
    from urllib2 import getproxies


CERT_SELFSIGNED_CA = os.path.join(os.path.dirname(__file__), 'selfsigned_ca.pem')

# Are system proxies set? System proxies are set in:
# - Environment variables (HTTP_PROXY/HTTPS_PROXY) on Unix;
# - System Configuration Framework on macOS;
# - Registry's Internet Settings section on Windows.
WITH_SYSTEM_PROXIES = bool(getproxies())


class DummyGeocoder(Geocoder):
    def geocode(self, location):
        geo_request = self._call_geocoder(location, raw=True)
        geo_html = geo_request.read()
        return geo_html if geo_html else None


class ProxyTestCase(unittest.TestCase):
    remote_website_http = "http://example.org/"
    remote_website_https = "https://example.org/"
    timeout = 5

    def setUp(self):
        self.proxy_server = ProxyServerThread(timeout=self.timeout)
        self.proxy_server.start()
        self.proxy_url = self.proxy_server.get_proxy_url()
github geopy / geopy / geopy / geocoders / tomtom.py View on Github external
from geopy.compat import quote, urlencode
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
from geopy.location import Location
from geopy.util import logger

__all__ = ("TomTom", )


class TomTom(Geocoder):
    """TomTom geocoder.

    Documentation at:
        https://developer.tomtom.com/search-api/search-api-documentation

    .. versionadded:: 1.15.0
    """

    geocode_path = '/search/2/geocode/%(query)s.json'
    reverse_path = '/search/2/reverseGeocode/%(position)s.json'

    def __init__(
            self,
            api_key,
            format_string=None,
            scheme=None,
github geopy / geopy / geopy / geocoders / opencage.py View on Github external
import warnings

from geopy.compat import string_compare, urlencode
from geopy.exc import GeocoderQueryError, GeocoderQuotaExceeded
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
from geopy.location import Location
from geopy.util import logger

__all__ = ("OpenCage", )


class OpenCage(Geocoder):
    """Geocoder using the OpenCageData API.

    Documentation at:
        https://opencagedata.com/api

    .. versionadded:: 1.1.0
    """

    api_path = '/geocode/v1/json'

    def __init__(
            self,
            api_key,
            domain='api.opencagedata.com',
            scheme=None,
            timeout=DEFAULT_SENTINEL,
github geopy / geopy / geopy / geocoders / navidata.py View on Github external
from geopy.compat import urlencode
from geopy.location import Location
from geopy.util import logger
from geopy.geocoders.base import Geocoder, DEFAULT_TIMEOUT

from geopy.exc import (
    GeocoderQueryError,
    GeocoderQuotaExceeded,
)


__all__ = ("NaviData", )


class NaviData(Geocoder):  # pylint: disable=W0223
    """
    Geocoder using the NaviData API. Documentation at:

        http://www.navidata.pl
    """

    def __init__(
            self,
            api_key=None,
            domain='api.navidata.pl',
            timeout=DEFAULT_TIMEOUT,
            proxies=None,
            user_agent=None,
    ):
        """
            .. versionadded:: 1.8.0
github alpha-beta-soup / errorgeopy / errorgeopy / geocoders.py View on Github external
.. _`geopy documentation`: http://geopy.readthedocs.io/en/latest/
        """
        self._config = config
        cfg = copy.deepcopy(config)
        if config:
            if not isinstance(config, dict):
                raise TypeError(
                    "GeocoderPool configuration must be a dictionary")
            self._geocoders = [Geocoder(gc, cfg[gc]) for gc in cfg]
        else:
            geocoders = geocoders or DEFAULT_GEOCODER_POOL
            if not isinstance(geocoders, collections.Iterable):
                raise TypeError(
                    "GeocoderPool member geocoders must be an iterable set")
            if not all(
                    isinstance(g, geopy.geocoders.base.Geocoder)
                    for g in geocoders):
                raise TypeError(
                    "GeocoderPool member geocoders must be geopy.geocoder geocoder"
                )
            self._geocoders = [
                Geocoder(type(gc).__name__, None) for gc in geocoders
            ]
github geopy / geopy / geopy / geocoders / geolake.py View on Github external
from geopy.compat import string_compare, urlencode
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
from geopy.location import Location
from geopy.util import join_filter, logger

__all__ = ("Geolake", )


class Geolake(Geocoder):
    """Geocoder using the Geolake API.

    Documentation at:
        https://geolake.com/docs/api

    Terms of Service at:
        https://geolake.com/terms-of-use

    .. versionadded:: 1.18.0
    """

    structured_query_params = {
        'country',
        'state',
        'city',
        'zipcode',
github geopy / geopy / geopy / geocoders / geonames.py View on Github external
GeocoderQuotaExceeded,
    GeocoderServiceError,
)
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
from geopy.location import Location
from geopy.timezone import (
    ensure_pytz_is_installed,
    from_fixed_gmt_offset,
    from_timezone_name,
)
from geopy.util import logger

__all__ = ("GeoNames", )


class GeoNames(Geocoder):
    """GeoNames geocoder.

    Documentation at:
        http://www.geonames.org/export/geonames-search.html

    Reverse geocoding documentation at:
        http://www.geonames.org/export/web-services.html#findNearbyPlaceName
    """

    geocode_path = '/searchJSON'
    reverse_path = '/findNearbyPlaceNameJSON'
    reverse_nearby_path = '/findNearbyJSON'
    timezone_path = '/timezoneJSON'

    def __init__(
            self,
github geopy / geopy / geopy / geocoders / banfrance.py View on Github external
from geopy.compat import urlencode
from geopy.geocoders.base import DEFAULT_SENTINEL, Geocoder
from geopy.location import Location
from geopy.util import logger

__all__ = ("BANFrance", )


class BANFrance(Geocoder):
    """Geocoder using the Base Adresse Nationale France API.

    Documentation at:
        https://adresse.data.gouv.fr/api

    .. versionadded:: 1.18.0
    """

    geocode_path = '/search'
    reverse_path = '/reverse'

    def __init__(
            self,
            domain='api-adresse.data.gouv.fr',
            format_string=None,
            scheme=None,
github M4rtinK / modrana / core / bundle / geopy / geocoders / google.py View on Github external
import json
  except ImportError:
    import simplejson as json       # pylint: disable-msg=F0401
except:
    print("geopy: using integrated non-binary simplejson, install proper simplejson package for better speed")
    import simplejson as json

import xml
from xml.parsers.expat import ExpatError

from geopy.geocoders.base import Geocoder,GeocoderError,GeocoderResultError
from geopy import Point, Location, util

from core.backports.six import string_types as basestring

class Google(Geocoder):
    """Geocoder using the Google Maps API."""
    
    def __init__(self, api_key=None, domain='maps.google.com',
                 resource=None, format_string='%s', output_format=None):
        """Initialize a customized Google geocoder with location-specific
        address information and your Google Maps API key.

        ``api_key`` should be a valid Google Maps API key. Required as per Google Geocoding API
        V2 docs, but the API works without a key in practice.

        ``domain`` should be the localized Google Maps domain to connect to. The default
        is 'maps.google.com', but if you're geocoding address in the UK (for
        example), you may want to set it to 'maps.google.co.uk' to properly bias results.

        ``resource`` is DEPRECATED and ignored -- the parameter remains for compatibility
        purposes.  The supported 'maps/geo' API is used regardless of this parameter.
github M4rtinK / modrana / core / bundle / geopy / geocoders / dot_us.py View on Github external
import getpass
from urllib import urlencode
from urllib2 import urlopen
from geopy.geocoders.base import Geocoder
from geopy import util
import csv

class GeocoderDotUS(Geocoder):
    def __init__(self, username=None, password=None, format_string='%s'):
        if username and (password is None):
            password = getpass.getpass(
                "geocoder.us password for %r: " % username
            )
        
        self.format_string = format_string
        self.username = username
        self.__password = password
    
    def get_url(self):
        username = self.username
        password = self.__password
        if username and password:
            auth = '%s@%s:' % (username, password)
            resource = 'member/service/namedcsv'