示例#1
0
 def from_address_and_timezone(cls, address, timezone_str, timeout=45):
     from geopy import geocoders
     geolocator = geocoders.ArcGIS()
     location = geolocator.geocode(query=address, timeout=timeout)
     city = City(name=address,
                 latitude=location.latitude,
                 longitude=location.longitude,
                 timezone=timezone_str)
     return city
示例#2
0
def geocodeHS(geocoder, hs_id, lookup_hs_name):
    if geocoder == 'arcgis':
        geolocator = geocoders.ArcGIS()
    elif geocoder == 'baidu':
        geolocator = geocoders.baidu()
    elif geocoder == 'geocodefarm':
        print("Troubleshooting AttributeError: 'NoneType' object has no attribute 'replace'")
        exit(0)
        # geolocator = GeocodeFarm()
    elif geocoder == 'geocoderdotus':
        geolocator = geocoders.GeocoderDotUS()
    elif geocoder == 'geonames':
        geolocator = geocoders.geonames()
    elif geocoder == 'googlev3':
        geolocator = geocoders.GoogleV3()
    elif geocoder == 'nominatim':
        geolocator = geocoders.Nominatim()
    elif geocoder == 'openmapquest':
        geolocator = geocoders.OpenMapQuest()
    elif geocoder == 'yandex':
        print('Do not use.  Russian site')
        exit(1)
    else:
        print('invalid geodocder specified')
        exit(1)
        
    try:
        return geolocator.geocode(lookup_hs_name, exactly_one=True, timeout=10)
    except exc.GeocoderQuotaExceeded:
        print(geocoder, ':\tGeocoderQuotaExceeded')
        exit(1)
    except exc.ConfigurationError:
        print(geocoder, ':\tConfigurationError')
        exit(1)
    except exc.GeocoderAuthenticationFailure:
        print(geocoder, ':\tGeocoderAuthenticationFailure')
        exit(1)
    except exc.GeocoderTimedOut:
        print(geocoder, ':\tGeocoderTimedOut')
        exit(1)
    except exc.GeocoderUnavailable:
        print(geocoder, ':\tGeocoderUnavailable')
        exit(1)
    except exc.GeocoderInsufficientPrivileges:
        print(geocoder, ':\tGeocderInsufficientPrivileges')
    except:
        return None