def dealWin(tamp, param):
    print(len(tamp), param)
    list2 = []
    dicts = {}
    users = {}
    com = {}
    for i in tamp:
        code = mzgeohash.encode((float(i[0]), float(i[1])), 7)
        user = i[2]
        coms = code + user

        tuples = (i[2], code, i[3])
        list2.append(tuples)
        dicts[code] = dicts.get(code, 0) + 1
        users[user] = users.get(user, 0) + 1
        com[coms] = com.get(coms, 0) + 1
    print(users)
    userss = sorted(com.items(), key=lambda x: x[1], reverse=True)
    print(dicts)
    print(com)
    print(userss)
    print(len(dicts.keys()), len(users.keys()), len(com.keys()))
    # print(dicts.keys())
    iindiff = {}
    for i in users.keys():
        for j in com.keys():
            if i == j[7:]:
                iindiff[i] = iindiff.get(i, 0) + 1
    # print(iindiff)
    iindiff = sorted(iindiff.items(), key=lambda x: x[1], reverse=True)
    print(iindiff)

    print(
        "============================================================================"
    )

    for i in users.keys():
        ii = []
        T = True
        for j in tamp:
            if j[2] == i:
                ii.append(mzgeohash.encode((float(j[0]), float(j[1])), 7))
        if len(ii) >= 2:
            co = ii[0]
            for jj in range(1, len(ii)):
                # ju = neigh(co,ii[jj])
                if neigh(co, ii[jj]) == 0:
                    T = False
                    break
                co = ii[jj]
        print(i, T, end="  ")
예제 #2
0
def city_point(city):
    """
    :param city:需要查询的城市
    :return:城市内的符合要求的等距坐标

    """
    list_p = []
    list_q = []
    # 根据接口查询城市边界的坐标
    url = city_url.format(0, GAODE_API_KEY, city)
    response = requests.get(url=url, headers=headers)
    data = response.json()
    # 获得城市边界坐标
    poly = data['districts'][0]['polyline']

    # 不匹配岛屿
    # poly = re.sub('\|.*\|',';',poly)
    # poly = poly.split("|")
    poly = re.sub('\|', ';', poly)
    # print(len(poly))
    # 将坐标进行处理,获得四个角落的坐标,构造一个矩形网络
    poly_list1 = poly.split(';')
    poly_list2 = list(zip(*[a.split(',') for a in poly_list1]))
    max_lng = max([int(a.replace('.', '')) for a in poly_list2[0]])
    min_lng = min([int(a.replace('.', '')) for a in poly_list2[0]])
    max_lat = max([int(a.replace('.', '')) for a in poly_list2[1]])
    min_lat = min([int(a.replace('.', '')) for a in poly_list2[1]])
    # 纬度1°为111.3195km,经度每度为111.3195cos(纬度)
    g = int((max_lng - min_lng) * 102.3022 / 4242640)
    g1 = [round(min_lng + i * 4242640 / 102.3022) for i in range(1, g)]
    h = int((max_lat - min_lat) * 111.3195 / 4242640)
    h1 = [round(min_lat + i * 4242640 / 111.3195) for i in range(1, h)]
    # 获得矩形网络内距离为4.2km的所有坐标
    while g1:
        g11 = g1.pop()
        # print(g11)
        for j in h1:
            list_p.append((g11, j))
    k = [a.split(',') for a in poly_list1]
    coords = [
        tuple(map(int, (i.replace('.', ''), j.replace('.', '')))) for i, j in k
    ]
    poly = MultiPoint(coords).convex_hull
    # 根据判断所有属于城市内的坐标并返回值

    for p in list_p:
        if poly.contains(Point(p)):

            list_q.append(p)
    # print(len(list_p))
    t_list = []

    for a, b in list_q:
        t_geohash = mzgeohash.encode((a / 1000000, b / 1000000), length=12)
        t_list.append((a / 1000000, b / 1000000, t_geohash))
    # print(t_list)
    return t_list
예제 #3
0
def winOperation(list1, id):
    list2 = []
    dicts = {}
    for i in list1:
        code = mzgeohash.encode((float(i[0]), float(i[1])), 5)
        tuples = (i[2], code, i[3])
        list2.append(tuples)
        dicts[code] = dicts.get(code, 0) + 1
    print("id : " + id, end="  ")
    print(dicts)
예제 #4
0
def calculatorZone(list1):

    # print(mzgeohash.encode((116.40957280303152, 39.9190363799492),5))
    dicts = {}
    for i in list1:
        t = (float(i[0]), float(i[1]))
        word = mzgeohash.encode(t, 5)
        print(word)
        dicts[word] = dicts.get(word, 0) + 1

    # print(type(dicts))
    dicts = sorted(dicts.items(), key=lambda x: x[1], reverse=True)
    print(dicts)
    print(str(len(dicts)))
예제 #5
0
 def get_videoswithneighbour(self, longitude, latitude, level, page):
     if not Rules.rule_geo(latitude=latitude, longitude=longitude, level=level):
         raise RuntimeError(errors.GEOINFORMATION_ERROR)
     longitude=round(float(longitude), 10)
     latitude=round(float(latitude), 10)
     level = int(level)
     geohash = mzgeohash.encode((longitude, latitude), level)
     neighbours = mzgeohash.neighbors(geohash).values()
     getvideos_SQL = SQL_refector.videos_getwithgeo(neighbours, level, page)
     getvideos_res = yield self.db.query_all(getvideos_SQL)
     if not getvideos_res:
         raise gen.Return([])
     else:
         datas = []
         for data in getvideos_res:
             datas.append(Jsonify.videojson(data))
         raise gen.Return(datas)
del stores['air_area_name_0']
del stores['air_genre_name_0']

#  geohash 替代聚类处理
import mzgeohash

train_loc = zip(stores['longitude'], stores['latitude'])
# test_loc = zip(test['longitude'],test['latitude'])
list_store_code_1 = []
list_store_code_2 = []
# list_test_code = []

print 'geohash feature'
for i in train_loc:
    list_store_code_1.append(mzgeohash.encode(i, length=6))
    list_store_code_2.append(mzgeohash.encode(i, length=8))

lbe = preprocessing.LabelEncoder()
stores['geohash'] = list_store_code_1
stores['geohash'] = lbe.fit_transform(stores['geohash'])

stores['geohash_sm'] = list_store_code_2
stores['geohash_sm'] = lbe.fit_transform(stores['geohash_sm'])

stores_count = stores.groupby(['geohash'],
                              as_index=False).count_observations.sum()
stores_count.rename(columns={'count_observations': 'geohash_visitors_sum'},
                    inplace=True)
stores = pd.merge(stores, stores_count, how='left', on=['geohash'])
def get_geohash(x):
    return mzgeohash.encode((float(x[0]), float(x[1])))
예제 #8
0
 def geohash(self):
     """Return 10 characters of geohash."""
     return mzgeohash.encode(self.point())
예제 #9
0
        if gps[1] < mid:
            lat_bs += "0"
            lat_range[1] = mid
            lat_range_tag[1] = 0
        else:
            lat_bs += "1"
            lat_range[0] = mid

    final_bs = "".join([lng_bs[i] + lat_bs[i] for i in range(len(lng_bs))])

    #converse 2 bit to 32 bit
    return "".join([
        converse_table[sum(
            [int(final_bs[x + 4 - k]) * pow(2, k) for k in range(5)])]
        for x in range(0, len(final_bs), 5)
    ])


lat_range = [18 * 1000, 54 * 1000]
lng_range = [70 * 1000, 136 * 1000]
geo_blocks = []
for i in range(lng_range[0], lng_range[1]):
    if i % 10000 == 0:
        print(lng_range[1] - lng_range[0]) / 1000
    for j in range(lat_range[0], lat_range[1]):
        geo_block = geohash.encode((i * 1.0 / 100000, j * 1.0 / 100000))
        if geo_block not in geo_blocks:
            geo_blocks.append(geo_block)

print len(geo_blocks)
from TDrive import ReadFromDirectory
import matplotlib.pyplot as plt
import  mzgeohash
from  TDrive import  Updatesample

# t = mzgeohash.encode((116.4036519233,39.9238241903),4)
# print(t)

print(mzgeohash.decode("wx4g"))

t = mzgeohash.encode((116.4406325205,39.9543963732),6)
print(t)

zone =[]
for i in mzgeohash.neighbors(mzgeohash.encode((116.4406325205,39.9543963732),6)).values():
    zone.append(i)
print(zone)
print(mzgeohash.neighbors(mzgeohash.encode((116.4406325205,39.9543963732),6)))

datas = ReadFromDirectory.FromDireGetData("J:\\DataSetForExp\\release\\test")
transDatas = ReadFromDirectory.CleanDataSet(datas)
transDatas.sort(key = lambda x:x[3],reverse = False)

transData = []
for ii in transDatas:
    # if(float(ii[0]) > 116.2075579685 and float(ii[0]) < 116.5632212466 and float(ii[1]) > 39.8333472137 and float(ii[1]) < 40.0326836503):
    transData.append(ii)
print(len(transData))
dicts = {}
target = ""
target = "wx4g3"