add: trace process
This commit is contained in:
parent
ea47212342
commit
ab2156fe30
@ -4,7 +4,7 @@ import gpxpy.gpx
|
|||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from geopy.distance import geodesic
|
from geopy.distance import geodesic
|
||||||
|
|
||||||
start_time = ['2022-02-22 17:42', '2022-02-24 19:44']
|
start_time = ['2022-04-01 17:34']
|
||||||
|
|
||||||
old = '<gpx creator="Health" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 \
|
old = '<gpx creator="Health" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 \
|
||||||
http://www.topografix.com/GPX/1/0/gpx.xsd" version="1.0" \
|
http://www.topografix.com/GPX/1/0/gpx.xsd" version="1.0" \
|
||||||
|
93
process.py
Normal file
93
process.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
import srtm
|
||||||
|
import math
|
||||||
|
import random
|
||||||
|
import numpy as np
|
||||||
|
from gpxpy import gpx
|
||||||
|
from geopy.distance import geodesic
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
from ChangeCoordinate import ChangeCoord
|
||||||
|
|
||||||
|
|
||||||
|
def cnm(n, m):
|
||||||
|
return math.factorial(n) / (math.factorial(n - m) * math.factorial(m))
|
||||||
|
|
||||||
|
|
||||||
|
def Bézier_curve(key_points, N=16):
|
||||||
|
n = len(key_points) - 1
|
||||||
|
points = []
|
||||||
|
for t in np.linspace(0, 1, N):
|
||||||
|
p0 = [0, 0]
|
||||||
|
for i, p in enumerate(key_points):
|
||||||
|
weight = cnm(n, i) * math.pow(t, i) * math.pow(1 - t, n - i)
|
||||||
|
p0[0] += p[0] * weight
|
||||||
|
p0[1] += p[1] * weight
|
||||||
|
points.append(p0)
|
||||||
|
return points
|
||||||
|
|
||||||
|
|
||||||
|
def process(velocity, max_dis, points, time0, filepath):
|
||||||
|
gpx_file = gpx.GPX()
|
||||||
|
gpx_track = gpx.GPXTrack()
|
||||||
|
gpx_segment = gpx.GPXTrackSegment()
|
||||||
|
|
||||||
|
gpx_file.tracks.append(gpx_track)
|
||||||
|
gpx_track.segments.append(gpx_segment)
|
||||||
|
|
||||||
|
p = None
|
||||||
|
k, dis = 0, 0
|
||||||
|
|
||||||
|
while dis <= max_dis:
|
||||||
|
i = int(dis // 1000) if dis // 1000 < len(velocity) else len(velocity) - 1
|
||||||
|
v = velocity[i] * random.gauss(1, 0.05)
|
||||||
|
|
||||||
|
p0 = points[k]
|
||||||
|
p0[0], p0[1] = coord.gcj02_to_wgs84(p0[0], p0[1])
|
||||||
|
p0 = gpx.GPXTrackPoint(
|
||||||
|
random.gauss(1, 1e-7) * p0[0],
|
||||||
|
random.gauss(1, 1e-7) * p0[1]
|
||||||
|
)
|
||||||
|
|
||||||
|
if p:
|
||||||
|
d = geodesic((p0.latitude, p0.longitude), (p.latitude, p.longitude)).m
|
||||||
|
dtime += d / v
|
||||||
|
else:
|
||||||
|
d, dtime = 0, 0
|
||||||
|
p0.time = time0 + timedelta(seconds=dtime)
|
||||||
|
p0.elevation = elevation_data.get_elevation(p0.latitude, p0.longitude)
|
||||||
|
gpx_segment.points.append(p0)
|
||||||
|
|
||||||
|
p = p0
|
||||||
|
k += 1
|
||||||
|
dis += d
|
||||||
|
k = 0 if k == len(points) else k
|
||||||
|
|
||||||
|
with open(filepath, 'w', encoding='utf-8') as f:
|
||||||
|
f.write(gpx_file.to_xml())
|
||||||
|
|
||||||
|
|
||||||
|
points = []
|
||||||
|
key_points = [
|
||||||
|
[40.003930, 116.325706],
|
||||||
|
[40.003512, 116.326248],
|
||||||
|
[40.003917, 116.326704],
|
||||||
|
[40.004956, 116.326640],
|
||||||
|
[40.005436, 116.326136],
|
||||||
|
[40.004935, 116.325642]
|
||||||
|
]
|
||||||
|
|
||||||
|
points.extend(Bézier_curve(key_points[0:3]))
|
||||||
|
points.extend(Bézier_curve(key_points[2:4]))
|
||||||
|
points.extend(Bézier_curve(key_points[3:]))
|
||||||
|
points.extend(Bézier_curve([key_points[-1], key_points[0]]))
|
||||||
|
|
||||||
|
coord = ChangeCoord()
|
||||||
|
elevation_data = srtm.get_data()
|
||||||
|
|
||||||
|
v = [6.25, 6.24, 6.19, 6.36, 6.01]
|
||||||
|
for i, k in enumerate(v):
|
||||||
|
v1 = int(k)
|
||||||
|
v2 = k - v1
|
||||||
|
v[i] = 1000 / (v1 * 60 + v2 * 100)
|
||||||
|
|
||||||
|
t0 = datetime.strptime('2022-04-22 17:38', '%Y-%m-%d %H:%M') - timedelta(hours=8)
|
||||||
|
process(v, 5010, points, t0, './20220422户外跑步.gpx')
|
@ -1,3 +1,4 @@
|
|||||||
gpxpy
|
ChangeCoordinate==1.1
|
||||||
geopy
|
geopy==2.2.0
|
||||||
ChangeCoordinate
|
gpxpy==1.5.0
|
||||||
|
SRTM.py==0.3.7
|
||||||
|
Reference in New Issue
Block a user