根据速度降低GPS点数

时间:2017-04-28 12:34:55

标签: r performance gps distance spatial

我试图在Speed的基础上删除经度和纬度点。如果速度不在给定阈值范围内,则在向量中添加终止经度和纬度对,否则忽略它并移动到下一个经度和纬度点。但我的代码不起作用。 以下是代码;

 while (i < length(longitude))
{
 library(geosphere)
 dist <- distm (c(longitude [j],Latitude[j]), c(longitude [i],Latitude[i]), 
 fun = distVincentyEllipsoid)
 distt <- append(distt, dist)
 time_vector <- time[j] - time[i]
 time_TT <- append(time_TT, time_vector*60)  # converting mints into seconds 
 speed <- distt/time_TT                      # Calculating speed 

 if!((speed <= speed + delta) & (speed >= speed - delta))

 {
  LON_S  <- append(LON_Speed, longitude [j])
  LAT_S  <- append(LAT_Speed, Latitude[j])

   }
   else break;
   i <- j 
   j <- i + 1
   }


 Data is 

 longitude <- round(c(48.7188021250007,
                 48.7188133749999,
                 48.7188291249998,
                 48.7188336250004, 
                 48.7188291250005, 
                 48.7188291250085
                 ), 8);

 Latitude <- round(c (2.39514523661229,
                 2.39512477447308, 
                 2.39472235230961,
                 2.39467460730213,
                 2.39467460730313, 
                 2.4), 8);

  time <- strptime(c('2017-04-06 09:15:00',
               '2017-04-06 09:30:00',
               '2017-04-06 09:40:00',
               '2017-04-06 09:50:00',
               '2017-04-06 09:55:00',
               '2017-04-06 10:56:00'),"%Y-%m-%d %H:%M:%S");

1 个答案:

答案 0 :(得分:1)

检查速度范围的条件始终为假。 LAssuming deltaspeed都是正值,speed总是小于(或等于)speed + delta,所以

if!((speed <= speed + delta) & (speed >= speed - delta))

第一个条件是speed <= speed + delta,它总是正确的 同样地,speed >= speed + delta始终为真,所以在括号内总是以true结尾。接下来,您应用not运算符,以便始终获得false 你必须这样:

MAX <- your maximum allowed speed 
MIN <- your minimum allowed speed
if ((speed >= MIN) & (speed <= MAX))
{
   #speed is within range
}
else
{
   #speed is outside the range
}