Exemplo n.º 1
0
def test_gaode_reverse():
    """ Expected result :
        http://restapi.amap.com/v3/geocode/regeo?output=xml&location=116.310003,39.991957&key=<用户的key>&radius=1000&extensions=all
    """
    g = geocoder.gaode(place, method='reverse', key='0716e5809437f14e3dd0793a5c6d2b13')
    assert g.ok
    assert g.country == u'中国'
    assert g.state == u'北京市'
    assert g.city == u'北京市'
    assert g.street == u'UBP东街'
Exemplo n.º 2
0
def addLocation(hc):
    query = """SELECT distinct CAST(start_loc_lat as float) as loc_lat, CAST(start_loc_lon as float) as loc_lon from ubi.trips_complete union SELECT distinct CAST(end_loc_lat as float) as loc_lat, CAST(end_loc_lon as float) as loc_lon from ubi.trips_complete where
start_day>='20190212' and start_day<='20190313'"""
    df=hive2pandas(hc, query)
    with open('/home/wchen/dsc/latlon2location_0312' + '.txt', 'w') as outfile:
        for x in range(len(df)):
            g = geocoder.gaode([df.iloc[x,0], df.iloc[x,1]], method='reverse', key='27522a3d9da8f4e80d6580c80d010d4c')
            adds = g.address
            if g.address is None:
                adds=''
            elif type(g.address)==list:
                adds=str(adds)
            outfile.write(df.iloc[x,0] + '\t' + df.iloc[x,1] + '\t' + adds.encode('utf-8') + '\n')
    print('Done with location!')
Exemplo n.º 3
0
def addLocation(hc, p):
    query = """SELECT distinct ROUND(CAST(start_loc_lat as float), 3) as loc_lat, ROUND(CAST(start_loc_lon as float), 3) as loc_lon from ubi.trips_complete union SELECT distinct ROUND(CAST(end_loc_lat as float), 3) as loc_lat, ROUND(CAST(end_loc_lon as float), 3) as loc_lon from ubi.trips_complete"""
    df=hive2pandas(hc, query)
    with open('/home/wchen/ubi/latlon2location_' + str(p) + '.txt', 'w') as outfile:
        for x in range(len(df)):
            if(int(df.iloc[x,0] * 10) % 10 == p):
                g = geocoder.gaode([df.iloc[x,0], df.iloc[x,1]], method='reverse', key='27522a3d9da8f4e80d6580c80d010d4c')
                adds = g.address
                if g.address is None:
                    adds=''
                elif type(g.address)==list:
                    adds=str(adds)
                outfile.write('%.3f'%(df.iloc[x,0]) + '\t' + '%.3f'%(df.iloc[x,1]) + '\t' + adds.encode('utf-8') + '\n')
    print('Done with location: ' + p)
Exemplo n.º 4
0
        if key not in d:
            d[key] = (city, province)
    print(len(d))


    df1 = pd.read_csv('res.txt', dtype='str')
    df1.columns = ['vin', 'lat', 'lon']
    lats = df1['lat'].tolist()
    lons = df1['lon'].tolist()


    print('reverse geocoding coords..')
    for lat, lon in zip(lats, lons):
        key = lat + '+' + lon
        if key not in d:
            g = geocoder.gaode([float(lat), float(lon)], method='reverse', key='0716e5809437f14e3dd0793a5c6d2b13')
            while not g.ok:
                print('retrying..')
                time.sleep(5)
                g = geocoder.gaode([float(lat), float(lon)], method='reverse', key='0716e5809437f14e3dd0793a5c6d2b13')
            d[key] = (g.city, g.state)
    print('done.')


    fields = ['city', 'province']
    df1[fields] = df1.apply(lambda row: pd.Series(d[row['lat']+'+'+row['lon']]), axis=1)
    df1 = df1.sort_values(by='vin')
    df1 = df1.loc[:, ['vin', 'lat', 'lon', 'city', 'province']]
    df1.to_csv('veh_locs.csv', encoding='utf-8')

    print('done.')
Exemplo n.º 5
0
def test_gaode():
    """ Expected result :
        http://restapi.amap.com/v3/geocode/geo?address=兆维华灯大厦,北京&output=XML&key=<用户的key>
    """
    g = geocoder.gaode(location, key='0716e5809437f14e3dd0793a5c6d2b13')
    assert g.ok