|
|
from idlelib import tooltip
|
|
|
from math import *
|
|
|
import queue
|
|
|
import sys
|
|
|
import time
|
|
|
import os
|
|
|
from datetime import datetime
|
|
|
import pymssql
|
|
|
import pandas as pd
|
|
|
import numpy as np
|
|
|
import datetime
|
|
|
import math
|
|
|
from folium import plugins
|
|
|
import folium
|
|
|
import os
|
|
|
|
|
|
sys.path.append(r'C:\Users\Wayson\Desktop')
|
|
|
from CarQuery import *
|
|
|
from Arc import *
|
|
|
from ArcMany import *
|
|
|
|
|
|
arc_objects=[]
|
|
|
Arc_many_count=[]
|
|
|
Arc_many_objects=[]
|
|
|
Arc_data2=[]
|
|
|
# 返回两个gps点的实际距离,x,y与米的换算约为1:111000。不同的比例尺换算不一样
|
|
|
def DistanceActual(geo1, geo2):
|
|
|
return pow(pow(float(geo1[0]) - float(geo2[0]), 2) + pow(float(geo1[1]) - float(geo2[1]), 2), 0.5) * 111000
|
|
|
|
|
|
|
|
|
# 如果起点定位数据跟道路的相差很远,则没有必要取该条arc
|
|
|
def CheckNecessary(arc, car_record):
|
|
|
if DistanceActual(arc.geometry_list[0], car_record.geo) > 1000:
|
|
|
if DistanceActual(arc.geometry_list[-1], car_record.geo) > 1000:
|
|
|
return False
|
|
|
else:
|
|
|
return True
|
|
|
|
|
|
|
|
|
def CalCost(arc, car_record):
|
|
|
cost = float("inf")
|
|
|
# CheckNecessary函数首先排除与起点定位点距离相差远的路段。/LOU
|
|
|
if CheckNecessary(arc, car_record):
|
|
|
# 下面if是计算这条道路上所有点跟目标点的最短距离小于10m才返回True。我们认为起点定位精度为10m
|
|
|
min_dist = float("inf")
|
|
|
for geo1 in arc.geometry_list:
|
|
|
tmp = DistanceActual(geo1, car_record.geo)
|
|
|
if tmp < min_dist:
|
|
|
min_dist = tmp
|
|
|
cost = min_dist
|
|
|
return cost
|
|
|
|
|
|
|
|
|
# 给定car_geo和car_direction,根据最短距离,计算在所有道路的Cost,返回Cost最小的道路id
|
|
|
def CalMinCostArcID(car_record):
|
|
|
min_cost = float("inf")
|
|
|
id = 0
|
|
|
# arc_objects存储着所有边的Arc对象实例,即所有路段信息。/LOU
|
|
|
for arc in arc_objects:
|
|
|
cost = CalCost(arc, car_record)
|
|
|
if cost < min_cost:
|
|
|
min_cost = cost
|
|
|
id = arc.id
|
|
|
return id
|
|
|
|
|
|
|
|
|
# 得到id为i的路段的密集点集合
|
|
|
def ArcmanyRecordsDivide(Arcmany_i):
|
|
|
Arcmany_index_start = sum(Arc_many_count[:Arcmany_i]) # 第i路段的起始索引位置
|
|
|
Arcmany_index_end = sum(Arc_many_count[:Arcmany_i + 1]) # 第i路段的终止索引位置
|
|
|
Arcmany_record_list = Arc_many_objects[Arcmany_index_start: Arcmany_index_end] # 每个路段的点集合
|
|
|
Arcmany_geo_list = [Arcmany_record.geometry_list2 for Arcmany_record in Arcmany_record_list] # 每个路段的点的(x,y)集合
|
|
|
return Arcmany_geo_list
|
|
|
|
|
|
def swap_loc(list):
|
|
|
temp = 0
|
|
|
for i in range(0,len(list)):
|
|
|
temp = list[i][1]
|
|
|
list[i][1] = list[i][0]
|
|
|
list[i][0] = temp
|
|
|
# arc_objects里的路段经纬度更新为点集合
|
|
|
for i in range(0, len(Arc_data2)): # 对每条路段循环
|
|
|
del arc_objects[i].geometry_list[0:4] # 删除第i条路段原有的(x,y)信息
|
|
|
Arcmany_record_list_i = ArcmanyRecordsDivide(i) # 提取第i条路段新的密集点(x,y)信息
|
|
|
for j in range(0, len(Arcmany_record_list_i)): # 对第i条路段新的密集点(x,y)信息循环
|
|
|
arc_objects[i].geometry_list.append(Arcmany_record_list_i[j]) # 在第i条路段(x,y)列加上 新的密集点(x,y)第j条信息
|
|
|
|
|
|
|