使用skyline算法查找运动点点周边的餐饮集
import pandas as pd
import time
from voronoi import voro_road
def skyline(longitude,latitude):
pd.set_option('precision', 14)
gbpoi_all = pd.read_csv('all_gbpoi_test.csv',header=None,encoding = "gbk",delimiter="\t")
#获取poi
gbpoi= pd.read_csv('all_gbpoi_test.csv',header=None,encoding = "gbk",delimiter="\t",usecols=[1,2])
quadrant1 = []
quadrant2 = []
quadrant3 = []
quadrant4 = []
for index,row in gbpoi.iterrows():
row[1]=row[1]-longitude
row[2]=row[2]-latitude
if row[1]>=0 and row[2]>=0:
quadrant1.append([index,row[1],row[2]])
if row[1]<0 and row[2]>0:
quadrant2.append([index,row[1],row[2]])
if row[1]<0 and row[2]<0:
quadrant3.append([index,row[1],row[2]])
if row[1]>0 and row[2]<0:
quadrant4.append([index,row[1],row[2]])
quadrant1_result = []
quadrant2_result = []
quadrant3_result = []
quadrant4_result = []
flag=True
for item in quadrant1:
for index in quadrant1:
if item[1]>index[1] and item[2]>index[2]: #非skyline点
flag=False
break
if flag==True:
quadrant1_result.append(item)
else:
flag = True
flag = True
for item in quadrant2:
for index in quadrant2:
if item[1] < index[1] and item[2] > index[2]:
flag = False
break
if flag == True:
quadrant2_result.append(item)
else:
flag = True
flag = True
for item in quadrant3:
for index in quadrant3:
if item[1] < index[1] and item[2] < index[2]:
flag = False
break
if flag == True:
quadrant3_result.append(item)
else:
flag = True
flag = True
for item in quadrant4:
for index in quadrant4:
if item[1] > index[1] and item[2] < index[2]:
flag = False
break
if flag == True:
quadrant4_result.append(item)
else:
flag = True
total_skyline=[]
for item in quadrant1_result:
total_skyline.append([gbpoi_all.iat[item[0],1],gbpoi_all.iat[item[0],2],gbpoi_all.iat[item[0],3]])
for item in quadrant2_result:
total_skyline.append([gbpoi_all.iat[item[0],1],gbpoi_all.iat[item[0],2],gbpoi_all.iat[item[0],3]])
for item in quadrant3_result:
total_skyline.append([gbpoi_all.iat[item[0],1],gbpoi_all.iat[item[0],2],gbpoi_all.iat[item[0],3]])
for item in quadrant4_result:
total_skyline.append([gbpoi_all.iat[item[0],1],gbpoi_all.iat[item[0],2],gbpoi_all.iat[item[0],3]])
return total_skyline
def getpos(lng1,lat1,lng2,lat2,step):
k =(lat2-lat1)/(lng2-lng1)
x = lng1+step
y = k * x
if x>lng2:
return 361,91
else:
return x,y
if __name__ == '__main__':
longitude=39.57554
latitude=115.735999
total_skyline=skyline(longitude,latitude)
for item in total_skyline:
print(item)
#调用路网维诺图
voro=voro_road()
#查所有skyline点所在维诺图区域
voro_result=voro.get_road_pos(total_skyline)
#查运动点所在区域
single_pos=voro.get_road_sigle_pos(longitude,latitude)
# 起点
lng1=39.57554
lat1=115.735999
# 终点
lng2=39.576548
lat2=115.743849
x_step=0.00000000000001 #步长
for i in range(0,100):
lng,lat=getpos(lng1,lat1,lng2,lat2,x_step)
if (lng!=361 and lat!=91):
total_skyline = skyline(lng, lat)
lng1 += x_step
for item in total_skyline:
print('****************************************************')
print(item)
time.sleep(10)
else:
break