import math
from pathlib import Path
import pandas as pd
import requests
from shapely import Point
from tool import file_util, tile_id_util
from tool.coord_util import TileManager
from tool.geotool import LineUtil
def get_interval_times(interval_list):
intervals = set([0.0, 1.0])
for interval in interval_list:
intervals.update(interval)
intervals = sorted(list(intervals))
times_interval_dict = {}
times_length_dict = {}
for i in range(len(intervals) - 1):
sub_inter = [intervals[i], intervals[i + 1]]
sub_inter_length = sub_inter[1] - sub_inter[0]
times = (list(map(lambda x: (sub_inter[0] >= x[0]) and (sub_inter[1] <= x[1]), interval_list))
.count(True))
if times in times_length_dict:
times_length_dict[times] += sub_inter_length
else:
times_length_dict[times] = sub_inter_length
if times in times_interval_dict:
times_interval_dict[times].append(sub_inter)
else:
times_interval_dict[times] = [sub_inter]
return times_length_dict, times_interval_dict
def get_pts_between_dis_range(pts, start_dis, end_dis, eps=1):
dis_cache = 0
flag = 0
ret = []
for i in range(0, len(pts) - 1):
cur_dis = LineUtil.sqrt_distance(pts[i + 1], pts[i])
sum_dis = dis_cache + cur_dis
if sum_dis < start_dis + eps:
dis_cache += cur_dis
continue
if (sum_dis >= start_dis + eps) and flag == 0:
percent = (start_dis - dis_cache) / cur_dis
left_pt = LineUtil.get_point_at_percent(pts[i], pts[i + 1], percent)
flag = 1
ret.append(left_pt)
if sum_dis > end_dis - eps:
percent = (end_dis - dis_cache) / cur_dis
right_pt = LineUtil.get_point_at_percent(pts[i], pts[i + 1], percent)
ret.append(right_pt)
break
ret.append(pts[i + 1])
dis_cache += cur_dis
return ret
def get_point_at_distance(pts1, pts2, distance: float):
sqrt_distance = math.sqrt((pts2[0] - pts1[0]) ** 2 + (pts2[1] - pts1[1]) ** 2)
percent = distance / sqrt_distance + 1
x = pts1[0] + (pts2[0] - pts1[0]) * percent
y = pts1[1] + (pts2[1] - pts1[1]) * percent
if len(pts1) > 2:
z = pts1[2] + (pts2[2] - pts1[2]) * percent
return x, y, z
else:
return x, y
if __name__ == '__main__':
intervals = [[0.1, 0.2], [0.05, 0.15], [0.3, 0.4]]
# print(interval_times(intervals))
# file_json = file_util.file2json("/Users/shilulu/Desktop/prod_road_task_ctf_merge_1709042338_13_15_2.json")
# tiles = []
# for i in file_json:
# tiles.append(i['tileid'])
# print(len(file_json))
# print(len(tiles))
# print(tiles)
# from tool.coord_tool import TileManager
#
tile_manager = TileManager()
print(Point(tile_manager.wgs84_to_gcj02(119.937649,31.73250909999)).wkt)
# print(Point(tile_id_util.get_tileid_center_point(15, 322147922)).wkt)
# print(tile_id_util.convert_lonlat_to_tileid(15, 116.5791175739112, 40.170322266060055))
# print(get_pts_between_dis_range([[0, 0], [1, 0], [2, 0], [3, 0]], 0.8, 2.5, 0.15))
#
# df = pd.read_csv("/Users/shilulu/Downloads/data-1709899085343.csv")
# print(df.head(1))
# l_slist = df['l_s'].tolist()
# l_elist = df['l_e'].tolist()
# zip_s_e = zip(l_slist, l_elist)
# s_e_list = list(zip_s_e)
# s_e_list = [[0,1],[0,1],[0,0.1172844976147933]]
# times_length_dict, times_interval_dict= get_interval_times(s_e_list)
# print(times_length_dict)
# print(times_interval_dict)
# coincide_times_list = sorted(list(times_interval_dict.keys()), reverse=True)
# print(coincide_times_list)
# print(get_point_at_distance((0, 0), (1, 0), 2.6))
网友评论