基于R/MATLAB中GPS坐标的标签路由



我有三个固定点说A,B和C以及它们之间的几个路线,它们可以按任何顺序。跳闸在A的A开始和结束。路由,固定点和参考点的图像。我有1000秒的GPS文件,我需要在其中标记所采用的路线。GPS文件记录纬度,经度(以度为单位(,速度,距离每秒的行进距离和累积距离。

我想到以下算法:从a,b和C点的每个路线上确定每个路由上的参考点(例如d(。B或C。由于其A GPS测量,可能没有与A,B或C相对应的确切点P>

现在,当我们向B或C移动时,开始从点开始计算累积。对此。最接近的参考点会给我路线。例如这个数字,我们说路线是BA。如果最近的点是2,则路线为ab。

现在,我们转到A,B或C的第二次出现,然后在距离D之后找到一个点,然后找到最接近该点的参考点。分配路线等。

请帮助我使用代码。R或MATLAB。

所以,我写了一个代码,其中包含很多循环。它对我来说很好,没有错误。大约需要9秒钟来处理15000行的单个文件,并确定我需要的所有8条路线。到目前为止,一切都很好。只是想找到一个更优化的程序或更快的程序。我是编程的初学者。

gpsdata <- read.csv(file = filename, header = TRUE)
####lat and long of route start/end points
# Route Start Point: Routes A and C on Cates Avenue
cateslat = 35.781999
cateslon = -78.668252
#Route Mid: Intersection of AC13, Morning Dove Road
morlat = 35.882035
morlon = -78.645653
#Route End: RTP 
rtplat = 35.895431
rtplon = -78.868958
}
#REFERENCE POINTS FOR ROUTE IDENTIFICATION ON EACH ROUTE 
{
routea_lat = 35.795400
routea_lon = -78.641243
routec_lat = 35.821031
routec_lon = -78.687069
route1_lat = 35.913527
route1_lon = -78.714348
route3_lat = 35.922331
route3_lon = -78.842865
}
##### ROUTE START POINT TOLERANCE in miles
route_tol = 0.02
##### Reference POINT TOLERANCE for Identifying Routes (in miles)
ref_tol = 0.5
##Calculation Starts Here
n = length(gpsdata$Timestamp) ##File length
#Find point q where we first reach starting route (within 0.01 miles)
for (i in 1:n){
if((distm(c(gpsdata$Longitude[i], gpsdata$Latitude[i]),c(cateslon, 
cateslat),fun = distHaversine)*0.000621371)<route_tol){
  q=i
  break
}
else
{
  q=1
}
} 
### First Route: Either A-Out or C-Out
for (i in q:n){
if((distm(c(gpsdata$Longitude[i], gpsdata$Latitude[i]),c(morlon, morlat),fun 
= distHaversine)*0.000621371)<route_tol){
r=i
break
}
else
{
r=1
}
}
gpsdata1=gpsdata[(q+1):r,]
for (i in 1:length(gpsdata1$Timestamp)){
if((distm(c(gpsdata1$Longitude[i], gpsdata1$Latitude[i]),c(routea_lon, 
routea_lat),fun = distHaversine)*0.000621371)<ref_tol){
gpsdata1$Route='A-Out'
break
} else if((distm(c(gpsdata1$Longitude[i], 
gpsdata1$Latitude[i]),c(routec_lon, routec_lat),fun = 
distHaversine)*0.000621371)<ref_tol){
  gpsdata1$Route='C-Out'
  break
} else{
  gpsdata1$Route='Error-Check Data'
}
}
#Second Route: possibilities- 1-Out, 3-Out, A-In, C-In
#From Here we can either go back to Cates Avenue or go to RTP
for (i in r:n){
if((distm(c(gpsdata$Longitude[i], gpsdata$Latitude[i]),c(rtplon, rtplat),fun 
= distHaversine)*0.000621371<route_tol) || +
 (distm(c(gpsdata$Longitude[i], gpsdata$Latitude[i]),c(cateslon, 
cateslat),fun = distHaversine)*0.000621371<route_tol)){
s=i
break
}
else
{
s=1
}
}
gpsdata2=gpsdata[(r+1):s,]
for (i in 1:length(gpsdata2$Timestamp)){
if((distm(c(gpsdata2$Longitude[i], gpsdata2$Latitude[i]),c(route1_lon, 
route1_lat),fun = distHaversine)*0.000621371)<ref_tol){
gpsdata2$Route='1-Out'
break
} else if((distm(c(gpsdata2$Longitude[i], 
gpsdata2$Latitude[i]),c(route3_lon, route3_lat),fun = 
distHaversine)*0.000621371)<ref_tol){
gpsdata2$Route='3-Out'
break
} else if((distm(c(gpsdata2$Longitude[i], 
gpsdata2$Latitude[i]),c(routea_lon, routea_lat),fun = 
distHaversine)*0.000621371)<ref_tol){
gpsdata2$Route='A-In'
break
} else if((distm(c(gpsdata2$Longitude[i], 
gpsdata2$Latitude[i]),c(routec_lon, routec_lat),fun = 
distHaversine)*0.000621371)<ref_tol){
gpsdata2$Route='C-In'
break
} else{
gpsdata2$Route='Error-Check Data'
}
}

最新更新