I am trying to make loops to calculate Speed for all "Longitude, Latitude and Timestamp" points. But loops are not working. Based on Min and Max values of a Speed i am filtering the points and saving them in other vectors. I just want to save latitude and longitude in one vector which satisfy condition of a Speed and save remaining latitude and longitude in other vector. Thanks
i = 1
j = i + 1
distt <<- 0
time_TT <- 0
#Speed
MIN <- 0.001
MAX <- 0.002
LON_S <-0
LAT_S <-0
z<-2
LON_SS <- 0
LAT_SS <- 0
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
speed <- round(speed, 3)
if ((speed[z] >= MIN) & (speed[z] <= MAX))
{
#speed is inside the range
LON_S <- append(LON_S, longitude [j])
LAT_S <- append(LAT_S, Latitude[j])
z <- z + 1
}
#speed is outside the range
LON_SS <- append(LON_SS, longitude [j])
LAT_SS <- append(LAT_SS, Latitude[j])
z <- z + 1
i = j; break
j <- j + 1
Aucun commentaire:
Enregistrer un commentaire