轨迹追踪.py 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Thu Dec 15 10:38:19 2022
  4. @author: 李堃
  5. """
  6. ###使用高德地图需要进行坐标转化
  7. import math
  8. pi = 3.1415926535897932384626
  9. a = 6378245.0
  10. ee = 0.00669342162296594323
  11. def wgs_gcj(lat, lon):
  12. dLat = transform_lat(lon - 105.0, lat - 35.0)
  13. dLon = transform_lon(lon - 105.0, lat - 35.0)
  14. radLat = lat / 180.0 * pi
  15. magic = math.sin(radLat)
  16. magic = 1 - ee * magic * magic
  17. sqrtMagic = math.sqrt(magic)
  18. dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi)
  19. dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * pi)
  20. mgLat = lat + dLat
  21. mgLon = lon + dLon
  22. return [mgLat,mgLon]
  23. def transform_lat(x, y):
  24. ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x))
  25. ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
  26. ret += (20.0 * math.sin(y * pi) + 40.0 * math.sin(y / 3.0 * pi)) * 2.0 / 3.0
  27. ret += (160.0 * math.sin(y / 12.0 * pi) + 320 * math.sin(y * pi / 30.0)) * 2.0 / 3.0
  28. return ret
  29. def transform_lon(x, y):
  30. ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x))
  31. ret += (20.0 * math.sin(6.0 * x * pi) + 20.0 * math.sin(2.0 * x * pi)) * 2.0 / 3.0
  32. ret += (20.0 * math.sin(x * pi) + 40.0 * math.sin(x / 3.0 * pi)) * 2.0 / 3.0
  33. ret += (150.0 * math.sin(x / 12.0 * pi) + 300.0 * math.sin(x / 30.0 * pi)) * 2.0 / 3.0
  34. return ret
  35. P = pd.read_csv("test_data.csv").values
  36. locations = P.tolist()
  37. zz=[ wgs_gcj(i[0], i[1]) for i in locations ]
  38. import folium
  39. import os
  40. import pandas as pd
  41. import numpy as np
  42. m = folium.Map(zz[0], zoom_start=16,
  43. tiles='http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}',
  44. attr='default')
  45. folium.PolyLine( # polyline方法为将坐标用实线形式连接起来
  46. zz, # 将坐标点连接起来
  47. weight=4, # 线的大小为4
  48. color='red', # 线的颜色为红色
  49. opacity=0.8, # 线的透明度
  50. ).add_to(m) # 将这条线添加到刚才的区域m内
  51. folium.Marker(
  52. location=zz[0],
  53. popup='start location',
  54. icon=folium.Icon(color='blue', icon='cloud') # 标记颜色 图标
  55. ).add_to(m)
  56. folium.Marker(
  57. location=zz[-1],
  58. popup='end location',
  59. icon=folium.Icon(color='red', icon='cloud') # 标记颜色 图标
  60. ).add_to(m)
  61. m.save("trace.html")