我已经为我的原始gps数据计算了停靠点,并且希望为我的输出导入target_id。请注意,输入文件的大小与输出的大小不同
id,时间,纬度,经度,海拔,精度,轴承,速度,卫星,提供者,hdop,vdop,pdop,geoidheigh,track_id,target_id 0,2018-08-19T14:29:28.000Z,52.38250042,9.725429713,101,18.224,,0,0,gps,``,'',1,75924 1,2018-08-19T14:29:31.000Z,52.38250202,9.725448912,101,11.792,,0,0,gps,0.8,0.7,1,46,1,75924 2,2018-08-19T14:29:32.631Z,52.38247107,9.725490814,102,9.648001,,0,15,gps,0.8,0.7,1,46,1,36337 3,2018-08-19T14:29:34.777Z,52.3825016,9.725443781,101,9.648001,,0,14,gps,``46,1,75924 4,2018-08-19T14:29:36.910Z,52.38250126,9.725439726,100,8.576,,0,15,gps,``46,1,75924 5,2018-08-19T14:29:39.039Z,52.38250164,9.72544436,100,7.504,,0,10,gps,``46,1,75924 6,2018-08-19T14:29:41.238Z,52.38246406,9.725492349,100,7.504,,0,0,gps,``46,1,36337 7,2018-08-19T14:29:43.387Z,52.38246311,9.725492558,100,6.432,,0,0,gps,1.5,0.8,1.7,46,1,36337 8,2018-08-19T14:29:45.548Z,52.38236408,9.725469972,100,6.432,166.9,2.63,9,gps,1.5,0.8,1.7,46,1,76994 9,2018-08-19T14:29:47.682Z,52.38228523,9.725550264,97,6.432,169.9,5.44,8,gps,``46,1,37044 10,2018-08-19T14:29:49.840Z,52.38216741,9.725602733,97,7.504,163.4,6.21,6,gps,``46,1,37044 11,2018-08-19T14:29:53.000Z,52.38205119,9.725687278,90,10.72,155.8,6.11,0,gps ,,,, 46,1,36330
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Input trajectory data
dataset = pd.read_csv("matched_all.csv")
m = dataset.query('track_id==1')
m_asarray = m.values
num_pt,num_attr = m_asarray.shape
# A basic model for stop detection based on velocity
velocity = m_asarray[:,7]
v_threshold = 0.02
is_stop = np.zeros(num_pt, dtype=bool)
for i in range(num_pt):
if velocity[i] < v_threshold:
is_stop[i] = 1
# plot
lat = m_asarray[:,2]
lon = m_asarray[:,3]
target_id = m_asarray[:,15]
plt.plot(lon,lat)
#plt.scatter(lon[is_stop],lat[is_stop])
# Clustering and Filtering
i = 0
count = 0 # Number of Stops
stops = np.zeros([0,2])
while i < num_pt:
if is_stop[i] == True :
j = 0
while i+j < num_pt and is_stop[i+j] == True :
j = j+1
a = np.mean(lat[i:i+j])
b = np.mean(lon[i:i+j])
coords = np.hstack((a,b))
stops = np.vstack((stops,coords))
count = count+1
i = i+j
continue
i = i+1
#print(stops)
print(stops)
plt.scatter(stops[:,1],stops[:,0],c='r',marker='o')
stops_as_df = pd.DataFrame(columns=['lat','lon'],data=stops)
file_name = 'stops_example.csv'
stops_as_df.to_csv(file_name,sep=',',encoding='utf-8')
````````````````````````