示例#1
0
def get_neighbors(geohashid):
    # Get the nearest neighbors
    # print('Passed in geohash value is ',geohashid)
    try:
        maplist = list(mzgeohash.neighbors(geohashid[:3]).values())
    except Exception, err:
        print('Error getting the nearest neighors', err)
        maplist = []
示例#2
0
def demand_analysis(geohash, time):
    neighbor = mzgeohash.neighbors(geohash)
    order_dict = {}
    income_dict = {}
    for key in neighbor.keys():
        geohash = neighbor[key]
        datas = find_mysql(geohash, time)
        order_count = len(datas)
        income = sum([data for data in datas])
        order_dict[key] = order_count
        income_dict[key] = income
    return order_dict, income_dict
示例#3
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)
def insert_weather_stations(data,name):
    from timeit import default_timer as timer
    from cassandra.cluster import Cluster
    from cassandra.query import dict_factory
    from cassandra.query import ordered_dict_factory
    from cassandra.concurrent import execute_concurrent_with_args

    from datetime import datetime
    import mzgeohash

    start_time = timer()
    cluster = Cluster()
    session = cluster.connect('xweather')

    # Assuming that the data is in the correct format for inserting to weather_stations

    query = "insert into weather_stations(geohash_id,station_id,elev,geohash_sub,lat,lon,source,timezone,tzoffset,neighbors) \
                                                 values(?,?,?,?,?,?,?,?,?,?)"
    prepared = session.prepare(query)
    query2 = "insert into neighbor_map_stations(geohash_sub,station_id,geohash_id,lat_long,neighbors) \
                values (?,?,?,?,?)"
    prepared2 = session.prepare(query2)

    ctr = 0
    for row in data:
        try:
            row = list(row.split(','))
            maplist = list(mzgeohash.neighbors(row[0][:3]).values())
            # print (row,maplist)
            bound = prepared.bind((row[0], row[1], float(row[2]), (row[3]), float(row[4]), float(row[5]), (row[6]),
                                   (row[7]), row[8], maplist))
            session.execute_async(bound)

            # Insert into neighbor_map_stations
            bound2 = prepared2.bind((row[3], row[1], row[0], list((row[4], row[5])), maplist))
            session.execute_async(bound2)
            ctr += 1
        except Exception,e:
            print('Error processing row due to  '+str(e)+ 'in '+str(name), row)
def get_geohash_w(geohash):
    this_neighbors = mzgeohash.neighbors(geohash)
    return this_neighbors['w']
def get_geohash_se(geohash):
    this_neighbors = mzgeohash.neighbors(geohash)
    return this_neighbors['se']
示例#7
0
# -*- coding:utf-8 -*-
def neigh(a, b):
    if b in mzgeohash.neighbors(a).values():
        return 1
    else:
        return 0
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"