Exemple #1
0
    def setUp(self):
        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 Data BC
        self.geolocator4 = DataBC()
        self.databcurlapi = "https://apps.gov.bc.ca/pub/geocoder/addresses.geojson"
        self.geolocators.append(self.geolocator4)
Exemple #2
0
 def setUpClass(cls):
     cls.geocoder = DataBC()
Exemple #3
0
 def test_user_agent_custom(self):
     geocoder = DataBC(user_agent='my_user_agent/1.0')
     self.assertEqual(geocoder.headers['User-Agent'], 'my_user_agent/1.0')
    hlbc = pd.read_excel('flagged_lists_manual_edits.xlsx',
                         sheet_name='Flagged HLBC Clinic List')
    writer = pd.ExcelWriter('working_list.xlsx', engine='openpyxl')

    # Looks for Flags in all the lists and isolates them for geocoding
    modified_partial_1 = modified[(modified['FLAG_1'] == 1)]
    modified_partial_2 = modified[(modified['FLAG_2'] == 1)]
    modified_partial_1 = modified_partial_1.dropna(how='all')
    modified_partial_2 = modified_partial_2.dropna(how='all')
    corrfac_partial = corrfac.where(corrfac['FLAG'] == 1)
    corrfac_partial = corrfac_partial.dropna(how='all')
    hlbc_partial = hlbc.where(hlbc['FLAG'] == 1)
    hlbc_partial = hlbc_partial.dropna(how='all')

    # Geocoding
    geolocator = DataBC(user_agent="ISU_filter")
    geocoded = RateLimiter(geolocator.geocode, min_delay_seconds=1 / 15)

    # Geocodes HLBC and Corrections Facilities
    lists_for_next_for = [corrfac_partial, hlbc_partial]
    for item in lists_for_next_for:
        item['GEO_LOCATION'] = item['ADDR_FOR_GEO'].astype(str).apply(
            lambda doot: geocoded(doot) if doot != 'nan' else '')
        item['GEO_ADDRESS'] = item['GEO_LOCATION'].apply(
            lambda loc: loc.address if loc else "")
        item['GEO_RAW'] = item['GEO_LOCATION'].apply(lambda loc: loc.raw
                                                     if loc else "")
        item['GEO_GPS'] = item['GEO_LOCATION'].apply(lambda loc: loc.point
                                                     if loc else "")
        item['GEO_LATITUDE'] = item['GEO_LOCATION'].apply(
            lambda loc: loc.latitude if loc else "")
Exemple #5
0
    writer = pd.ExcelWriter('EXAMPLE_FINAL.xlsx', engine='openpyxl')
    CPSBC = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx', 'CPSBC Modified')
    WALKIN = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx',
                      'Walk-in Clinic List')
    CORR_FAC = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx',
                        'Corrections Facilities List')
    GSR = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx', 'GSR List')
    HOSP = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx', 'Hospitals List')
    UPCC = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx', 'UPCC List')
    QFD = Modified('materials\\EXAMPLE_INPUT_STEP2.xlsx', 'QFD List')
    CHSA = Modified('materials\\PC_CHSA.csv', sheetname=None)
    REGION = Modified('materials\\bc_health_region_master_2018.xlsx', 'CHSA')

    print('Geocoding Start')
    input_val = input('Please Enter Your Company Name (No Spaces): ')
    geolocator = DataBC(user_agent=input_val)
    geocoded = RateLimiter(geolocator.geocode, min_delay_seconds=1 / 15)
    print('Geocoding CPSBC List')
    CPSBC.geocode_flags(geolocator, geocoded, CPSBC_mod=True)
    print('Geocoding Walk-in Clinic List')
    WALKIN.geocode_flags(geolocator, geocoded)
    print('Geocoding Corrections Facilities List')
    CORR_FAC.geocode_flags(geolocator, geocoded)
    print('Geocoding GSR List')
    GSR.geocode_flags(geolocator, geocoded)
    print('Geocoding Hospital List')
    HOSP.geocode_flags(geolocator, geocoded)
    print('Geocoding UPCC List')
    UPCC.geocode_flags(geolocator, geocoded)
    print('Geocoding QFD List')
    QFD.geocode_flags(geolocator, geocoded)
def main(path_in):
    geolocator = DataBC()
    print 'loading', path_in
    fpin = open(path_in, 'r')

    reader = csv.DictReader(fpin)
    d_list = []
    for row in reader:
        d = dict(STREET_NAME=row['STREET_NAME'],
                 STREET_NUMBER=row['STREET_NUMBER'],
                 YEAR=row['YEAR'],
                 VALUE=row['VALUE'])

        if d['STREET_NUMBER'].endswith('.0'):
            d['STREET_NUMBER'] = d['STREET_NUMBER'][:-2]

        if d['YEAR'].endswith('.0'):
            d['YEAR'] = d['YEAR'][:-2]

        d_list.append(d)

    y = str(int(d_list[1]['YEAR']))
    fpout = open('../data/property_tax_06_15/latlong_property_tax_'+ str(y) + '.csv', 'w')
    fpout.write('YEAR,VALUE,STREET_NUMBER,STREET_NAME,LATITUDE,LONGITUDE\n')

    random.shuffle(d_list)
    n_lines = float(len(d_list))
    curr_line = 0
    for d in d_list:
        curr_line += 1
        st_num = str(int(d['STREET_NUMBER']))
        st_name = str(d['STREET_NAME'])
        
        if (st_name, st_num) in local_db:
            latitude, longitude = local_db[(st_name, st_num)]
        else:
            print 'querying...'      
            address = st_num + ' ' + st_name + ' Vancouver BC Canada'

            got_it = False
            delay = 1
            while not got_it:
                try:
                    sleep(1)
                    location = geolocator.geocode(address)
                    got_it = True
                except (GeopyError, SSLError) as e:
                    delay *= 2
                    got_it = False
                    print 'try again...'

            latitude = "{:.15f}".format(location.latitude)
            longitude = "{:.15f}".format(location.longitude)
        
        curr_value = str(float(d['VALUE']))

        fpout.write(str(y) + ',' + curr_value + ',' + st_num + ',' + st_name + ',' + latitude + ',' + longitude + '\n')
        print str(100 * curr_line/n_lines) + '%, ' + str(y) + ',' + curr_value + ',' + latitude + ',' + longitude + ', '+ st_num, st_name
        local_db[(st_name, st_num)] = (latitude, longitude)

    fpin.close()
    fpout.close()
 def test_user_agent_custom(self):
     geocoder = DataBC(user_agent='my_user_agent/1.0')
     assert geocoder.headers['User-Agent'] == 'my_user_agent/1.0'
'''Should redo this script using argparse!!!!!!

Query sentinel-2 products over a given point (alternately, a place name). Later: tile-ID of interest. Restrict for time?
'''
import os
import sys
import math
foot_print = 'Intersects(51.0602686,-120.9083258)'  # default location: Kamloops
# VICTORIA: (48.4283334, -123.3647222)

fpfn = None
if len(sys.argv) > 1:
    if not os.path.exists(sys.argv[1]):
        import geopy  # python geocoder
        from geopy.geocoders import DataBC
        geolocator = DataBC()  # user_agent = "my-application")
        location = geolocator.geocode(sys.argv[1])
        print(location.address)
        print((location.latitude, location.longitude))
        foot_print = 'Intersects(' + str(location.latitude) + ',' + str(
            location.longitude) + ')'
    else:
        fpfn = sys.argv[1]
        foot_print = open(fpfn).read().strip()

# save username and password to files:
user_, pass_ = None, None
if not os.path.exists('./.user'):
    user_ = input('please enter your copernicus username:'******'./.user', 'wb').write(user_.encode())
    print('username written to ./.user')
Exemple #9
0
 def make_geocoder(cls, **kwargs):
     return DataBC(**kwargs)
import os
import datetime
import random
import numpy as np
import pandas as pd
import multiprocessing as mp
import glob
from geopy.geocoders import Nominatim, Photon, DataBC, ArcGIS
from geopy.exc import GeocoderServiceError, GeocoderTimedOut

__encoder__ = [ArcGIS(timeout=100), DataBC(timeout=100)]


def to_str(text):
    # this is the encoder to decode bytes into str

    if isinstance(text, bytes):
        value = text.decode('utf-8')
    else:
        value = text
    return value


def logging_info(address):
    # this is a simple log to store the transformed physical address.

    with open('log_info.txt', 'a+') as log_info:
        log_info.write(address + '\n')
    log_info.close()

Exemple #11
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)