I have calculated distance between 2 points on geolife dataset by using 2 methods and both are giving a different value.
for the 1st method, I have used the harvesine distance formula
below is the code:
for(i in 905:921){
geodistt[i] <- distm (c(lon1=filename$Longitude[i-1], lat1=filename$Latitude[i-1]), c(lon2=filename$Longitude[i], lat2=filename$Latitude[i]), fun = distHaversine)
}
filename2 <- data.frame(filename,tdiff,geodist)
for the 2nd method, I have used below code and considered Altitude,
for(i in 905:921){
Vincenty <- distance(lat1=filename$Latitude[i-1],lon1=filename$Longitude[i-1],lat2=filename$Latitude[i],lon2=filename$Longitude[i])
DirectDistance <- as.numeric(Vincenty[5]) # the fifth element of the output frame is the distance between the points.
#To be more accurate, we also take into account difference in altitude between the points
AltitudeChange <- abs(filename$Altitude[i]-filename$Altitude[i-1])
if(AltitudeChange!=0)
geodistt[i] <- sqrt(DirectDistance^2+AltitudeChange^2)
else
geodistt[i] <- DirectDistance
}
filename1 <- data.frame(filename,tdiff,geodistt)
print(filename1)
Output for filename2 output for filename1
both the outputs are different.
Outputs are attached.
Could you please suggest which method I should use. Do I need to consider Altitude. Please suggest