Пример #1
0
 def setUpClass(cls):
     cls.delta = 0.04
     cls.geocoder = GeocodeFarm(
         # None api_key will use free tier on GeocodeFarm.
         api_key=env.get('GEOCODEFARM_KEY'),
         timeout=10,
     )
Пример #2
0
 def test_authentication_failure(self):
     """
     GeocodeFarm authentication failure
     """
     self.geocoder = GeocodeFarm(api_key="invalid")
     with self.assertRaises(exc.GeocoderAuthenticationFailure):
         address = '435 north michigan ave, chicago il 60611'
         self.geocoder.geocode(address)
Пример #3
0
 def test_authentication_failure(self):
     self.geocoder = GeocodeFarm(api_key="invalid")
     with pytest.raises(exc.GeocoderAuthenticationFailure):
         self.geocode_run(
             {"query": '435 north michigan ave, chicago il 60611'},
             {},
             expect_failure=True,
         )
Пример #4
0
 def test_authentication_failure(self):
     """
     GeocodeFarm authentication failure
     """
     self.geocoder = GeocodeFarm(api_key="invalid")
     try:
         with self.assertRaises(exc.GeocoderAuthenticationFailure):
             address = '435 north michigan ave, chicago il 60611'
             self.geocoder.geocode(address)
     except exc.GeocoderTimedOut:
         raise unittest.SkipTest("GeocodeFarm timed out")
    def __init__(self):
        self.geocoders = [
            TimedGeocoder(Nominatim()),
            TimedGeocoder(GoogleV3()),
            TimedGeocoder(Yandex()),
            TimedGeocoder(ArcGIS()),
            TimedGeocoder(GeocodeFarm()),
            TimedGeocoder(Photon())
        ]

        self.next = 0
        self.size = len(self.geocoders)
Пример #6
0
    def setUp(self):
        self.address = "Sunnersta"  #static address to be found

        self.address2 = "Mackenzie"  #static address for DataBC only

        self.userlocation = (59.8585107, 17.6368508)

        self.addrNone = "abcdefghijklmnopqrstuvwxyz zyxwvutsrqponmlkjihgfedcba"  #non-existing address
        self.scheme = "https"
        self.plainscheme = "http"

        #set up for geocodeFarm
        self.geolocator5 = GeocodeFarm()
        self.geourlapi = "https://www.geocode.farm/v3/json/forward/"
Пример #7
0
 def setUpClass(cls):
     cls.delta = 0.04
     cls.geocoder = GeocodeFarm(
         api_key=env['GEOCODEFARM_KEY'],
         format_string="%s US"
     )
Пример #8
0
                pass
    except (KeyboardInterrupt, EOFError):
        exit(0)


if __name__ == '__main__':
    entry = {}

    entry['name'] = input('Name> ')

    entry['type'] = choose(
        ['school', 'company', 'research institute', 'other'], 'Type> ')

    address = input('Address> ')

    geolocator = GeocodeFarm()
    location = geolocator.geocode(address, timeout=15)
    if location is None:
        print('Geocoder failed')
        exit()

    entry['lat'] = location.latitude
    entry['long'] = location.longitude

    if location.longitude < -28:  # Recife, Brazil @ -34, Reykjavik, Iceland @ -22 - still not correct for eastern Russia!
        datafile = 'america'
    else:
        datafile = choose(datafiles, 'Chose a datafile> ')

    include_address = choose(['yes', 'no'], 'Include address in entry?> ')
    if include_address == 'yes':
Пример #9
0
 def test_user_agent_custom(self):
     geocoder = GeocodeFarm(user_agent='my_user_agent/1.0')
     self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0')
Пример #10
0
 def test_user_agent_custom(self):
     geocoder = GeocodeFarm(
         user_agent='my_user_agent/1.0'
     )
     assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0'
Пример #11
0
import hashlib
import re

import numpy as np

# The geolocators in geopy that do not expect api_key
from geopy.geocoders import GeocodeFarm, Yandex, ArcGIS

from db import Session
from db import Query

locators = [GeocodeFarm(), ArcGIS()]


def _query(session, hashcode, provider):
    return (session.query(Query).filter(Query.hashcode == hashcode,
                                        Query.provider == provider).first())


def cached_query(address, provider):
    address = re.sub(r"\s+", " ", address.upper())
    session = Session(expire_on_commit=False)
    provider_name = provider.__class__.__name__
    hashcode = hashlib.md5(bytes(address, encoding="utf-8")).hexdigest()
    cached = _query(session, hashcode, provider_name)
    if not cached:
        try:
            response = provider.geocode(address)
        except Exception as e:
            print(e)
            response = None
Пример #12
0
 def make_geocoder(cls, **kwargs):
     return GeocodeFarm(
         # None api_key will use free tier on GeocodeFarm.
         api_key=env.get('GEOCODEFARM_KEY'),
         timeout=10,
         **kwargs)
Пример #13
0
    def setUp(self):
        self.address = "Sunnersta"  #static address to be found

        self.address2 = "Mackenzie"  #static address for DataBC only

        self.userlocation = (59.8585107, 17.6368508)

        self.addrNone = "abcdefghijklmnopqrstuvwxyz zyxwvutsrqponmlkjihgfedcba"  #non-existing address
        self.scheme = "https"
        self.plainscheme = "http"
        self.geolocators = []

        #set up for Google
        self.geolocator1 = GoogleV3()
        self.googleurl = "https://maps.googleapis.com/maps/api/geocode/json"
        self.googledomain = "maps.googleapis.com"
        self.geolocators.append(self.geolocator1)

        #set up for ArcGIS
        self.geolocator2auth = ArcGIS("asailona", "uppsala00",
                                      "asailona.maps.arcgis.com")
        self.geolocator2 = ArcGIS()
        self.arcgisurl = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/find"
        self.arcgisgenerate = "https://www.arcgis.com/sharing/generateToken?username=asailona&password=uppsala00&expiration=3600&f=json&referer=asailona.maps.arcgis.com"
        self.geolocators.append(self.geolocator2auth)
        self.geolocators.append(self.geolocator2)

        #set up for Bing
        self.geolocator3auth = Bing(
            "AjIo4Ums4724tF5U5V7t91SHwwvjm8GP8wf0b3HZmVJWVQLlGJtSwv04IlwJ6971")
        self.bingapikey = "AjIo4Ums4724tF5U5V7t91SHwwvjm8GP8wf0b3HZmVJWVQLlGJtSwv04IlwJ6971"
        self.bingurlapi = "https://dev.virtualearth.net/REST/v1/Locations"
        self.geolocators.append(self.geolocator3auth)

        #set up for Data BC
        self.geolocator4 = DataBC()
        self.databcurlapi = "https://apps.gov.bc.ca/pub/geocoder/addresses.geojson"
        self.geolocators.append(self.geolocator4)

        #set up for geocodeFarm
        self.geolocator5 = GeocodeFarm()
        self.geourlapi = "https://www.geocode.farm/v3/json/forward/"
        self.geolocators.append(self.geolocator5)

        #set up for GeoNames
        self.geolocator6 = GeoNames(None, "asailona")
        self.gnameapi = "http://api.geonames.org/searchJSON"
        self.geolocators.append(self.geolocator6)

        #set up for MapZen
        self.geolocator7 = Mapzen("mapzen-yJXCFyc")
        self.mapzenapikey = "mapzen-yJXCFyc"
        self.mapzenapi = "https://search.mapzen.com/v1/search"
        self.geolocators.append(self.geolocator7)

        #set up for OpenCage
        self.geolocator8 = OpenCage("1aea82c9f55149dc1acc6ae04be7747c")
        self.openapikey = "1aea82c9f55149dc1acc6ae04be7747c"
        self.opendomain = "api.opencagedata.com"
        self.openapi = "https://api.opencagedata.com/geocode/v1/json"
        self.geolocators.append(self.geolocator8)

        #set up for Open Street Map
        self.geolocator9 = Nominatim()
        self.osmdomain = "nominatim.openstreetmap.org"
        self.osmapi = "https://nominatim.openstreetmap.org/search"
        self.geolocators.append(self.geolocator9)

        #set up for Photon
        self.geolocator10 = Photon()
        self.photondomain = "photon.komoot.de"
        self.photonapi = "https://photon.komoot.de/api"
        self.geolocators.append(self.geolocator10)

        #set up for vincenty distance test cases
        self.myLocation = Point(59.849904, 17.621000)
        self.northPole = Point(90.0, 0.0)
        self.southPole = Point(-90.0, 0.0)
        self.antiPodal1 = Point(0.0, 0.0)
        self.antiPodal2 = Point(0.5, 179.7)
        self.earthCircunference = Distance(2 * math.pi * EARTH_RADIUS)