Calculate total miles traveled from vectors of lat / lon

前端 未结 3 566
我在风中等你
我在风中等你 2020-12-02 02:10

I have a data frame with data about a driver and the route they followed. I\'m trying to figure out the total mileage traveled. I\'m using the geosphere packa

3条回答
  •  天涯浪人
    2020-12-02 02:45

    library(geodist)
    geodist(df, sequential = TRUE, measure = "geodesic") # sequence of distance increments
    sum(geodist(df, sequential = TRUE, measure = "geodesic")) # total distance in metres
    sum(geodist(df, sequential = TRUE, measure = "geodesic")) * 0.00062137 # total distance in miles
    

    Geodesic distances are necessary here because of the long distances involved. The result is 1013.915, slightly different from less-accurate Vincenty distances of geosphere. Street network distances can also be calculated with

    library(dodgr)
    dodgr_dists(from = df)
    

    ... but there has to be a street network, which is not the case for (lat = 76, lon = -110). Where there is a street network, that will by default give you all pair-wise distances routed through the street network , from which the sequential increments are the off-diagonal.

提交回复
热议问题