示例#1
0
def async_request_three(location, ws, session, index, locations_list, loc_col_index, lat_col_index, long_col_index):
    global total, threads, here_id, here_code, total_threads
    time.sleep((random.random() * 10))
    try:
        arc = geocoder.here(location, app_id = here_id, app_code = here_code)
        l = []
        if arc.ok:
#             l = arc.latlng
    #         l.append(arc.json[0])
    #         l.append(arc.json[1])
            l.append(arc.json['lat'])
            l.append(arc.json['lng'])
            cell = ws.cell(row=index+2, column=loc_col_index + 1)
            name = str(locations_list[index])
            if name is not None and name != '' and name != '' and not pd.isnull(name):
                cell.value = capitalizeWords(str(locations_list[index]))
            else:
                cell.value = ''
            cell = ws.cell(row=index + 2, column=lat_col_index + 1)
            cell.value = l[0]
            cell = ws.cell(row=index + 2, column=long_col_index + 1)
            cell.value = l[1]
        else:
            Thread(target=async_request, args=(location, ws, session, index, locations_list, loc_col_index, lat_col_index, long_col_index))
            threads.append(t)
            t.start()
            total += 1
            total_threads += 1
    except:
        t = Thread(target=async_request, args=(location, ws, session, index, locations_list, loc_col_index, lat_col_index, long_col_index))
        threads.append(t)
        t.start()
        total += 1
        total_threads += 1
示例#2
0
def get_coordinates(address):
    api_key = {
        'app_id': "jmkpDC63yWS" + "bK3644Zdi",
        "app_code": "lBPRtQcZI" + "yXgWurwgzCUkw"
    }
    g = geocoder.here(address,
                      app_id=api_key['app_id'],
                      app_code=api_key['app_code'])
    return g.json
示例#3
0
def test_here_with_bbox():
    g = geocoder.here(winnetka, bbox=winnetka_bbox)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 2
    assert fields_count >= 11

    for result in g:
        assert (result.lng >= winnetka_bbox[0]) and (result.lng <= winnetka_bbox[2])
        assert (result.lat >= winnetka_bbox[1]) and (result.lat <= winnetka_bbox[3])
示例#4
0
def geocode(address, here_app_id, here_app_code):
    '''
   Wraps exception handling around geocode
    '''
    try:
        return geocoder.here(address,
                             app_id=here_app_id,
                             app_code=here_app_code).latlng
    except IndexError:
        return [np.nan, np.nan]
示例#5
0
def test_here_with_bbox():
    g = geocoder.here(winnetka, bbox=winnetka_bbox)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 2
    assert fields_count >= 11

    for result in g:
        assert (result.lng >= winnetka_bbox[0]) and (result.lng <=
                                                     winnetka_bbox[2])
        assert (result.lat >= winnetka_bbox[1]) and (result.lat <=
                                                     winnetka_bbox[3])
示例#6
0
 def geocode(self, address, session):
     # url = 'http://localhost/nominatim/'
     if self.offline:
         url = 'localhost'
         self.g = geocoder.osm(address, url=url, session=session)
     if self.kind == 'arcgis':
         self.g = geocoder.arcgis(address, session=session)
     if self.kind == 'here':
         self.g = geocoder.here(address, session=session, app_id=here_app_id, app_code=here_app_key)
     if self.kind == 'bing':
         self.g = geocoder.bing(address, session=session, key=bing_key)
     res = processs_geojson(self.g)
     return res
示例#7
0
文件: models.py 项目: Clarson8/RAMS
 def set_lat_lon(self):
     try:
         query_string = (',').join([
             self.address or '', self.apartment or '', self.city or '',
             self.state or '', self.zip_code or ''
         ])
         g = geocoder.here(query_string,
                           app_id=settings.HERE_APP_ID,
                           app_code=settings.HERE_APP_CODE)
         self.latitude = g.json['lat']
         self.longitude = g.json['lng']
     except:
         pass
示例#8
0
import json
import geocoder

orignalJson = None
newJson = {}
with open("data.json", "r") as f:
    orignalJson = json.loads(f.read())

for counter in range(0, len(orignalJson)):
    try:
        g = geocoder.here(orignalJson[counter]["Nationality"],
                          app_id='DA1Z4YGFPP1CgZfq4mB9',
                          app_code='4FHp0V77LSCZ6On60TsM_g')
        newJson[counter] = orignalJson[counter]
        newJson[counter]["Latitude"] = g.latlng[0]
        newJson[counter]["Longitude"] = g.latlng[1]
        print(str(counter) + "----------" + str(newJson[counter]["ID"]))
    except Exception as e:
        print(e)
        pass

with open("dataV2.json", "w") as u:
    json.dump(newJson, u)
    print("File update complete!")
示例#9
0
def test_here():
    g = geocoder.here(location)
    assert g.ok
    assert g.city == city
示例#10
0
def test_here_reverse():
    g = geocoder.here(ottawa, method='reverse')
    assert g.ok
示例#11
0
def test_here():
    g = geocoder.here(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 4
    assert fields_count >= 13
示例#12
0
def test_here():
    g = geocoder.here(location)
    assert g.ok
    assert g.city == city
示例#13
0
def test_here_reverse():
    g = geocoder.here(ottawa, method='reverse')
    assert g.ok
示例#14
0
import geocoder
import csv
#import time

rows = []
fieldnames = [
    'dwellingType', 'recordID', 'dateIssued', 'permitType', 'permitValuation',
    'units', 'address', 'contractor', 'statCode', 'neighborhood', 'postal',
    'confidence', 'lat', 'lng'
]

# File name to be geocoded
with open('input.csv') as f:
    reader = csv.DictReader(f, delimiter=',')
    for line in reader:
        g = geocoder.here(line['address'],
                          app_id='app id would go here',
                          app_code='app code would go here')

        # Add the CSV line data into the Geocoder JSON result
        result = g.json
        result.update(line)

        # Store Geocoder results in a list to save it later
        rows.append(result)

with open('results.csv', 'a') as f:
    writer = csv.DictWriter(f, fieldnames=fieldnames, extrasaction='ignore')
    writer.writeheader()
    writer.writerows(rows)
    #time.sleep(2)
示例#15
0
def test_here():
    g = geocoder.here(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count >= 4
    assert fields_count >= 13