Analogue of the dist() function, but calculating great circle distances. Points should be input as a two-column matrix or dataframe with longitude in the first column and latitude in the second.

dist_gc(x)

Arguments

x

a two-column matrix or dataframe with longitude in the first column and latitude in the second

Examples

london_lon <- runif(20, min = -0.2, max = 0) london_lat <- runif(20, min = 51.47, max = 51.53) some_data <- data.frame(longitude = london_lon, latitude = london_lat) head(some_data)
#> longitude latitude #> 1 -0.13323534 51.47746 #> 2 -0.05014547 51.47691 #> 3 -0.01736840 51.49200 #> 4 -0.15913419 51.49826 #> 5 -0.10564888 51.51705 #> 6 -0.12296338 51.49942
distance_matrix <- dist_gc(some_data) head(distance_matrix)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 0.000000 5.754724 8.184307 2.926583 4.798356 2.543430 0.8298242 5.693748 #> [2,] 5.754724 0.000000 2.822515 7.910953 5.889254 5.629028 4.9390390 9.195601 #> [3,] 8.184307 2.822515 0.000000 9.838804 6.715110 7.356464 7.4203420 10.358457 #> [4,] 2.926583 7.910953 9.838804 0.000000 4.250494 2.507151 3.5877550 3.157799 #> [5,] 4.798356 5.889254 6.715110 4.250494 0.000000 2.297294 4.6811602 3.664146 #> [6,] 2.543430 5.629028 7.356464 2.507151 2.297294 0.000000 2.5936844 3.803821 #> [,9] [,10] [,11] [,12] [,13] [,14] [,15] #> [1,] 5.959459 2.5549189 3.796139 7.124425 4.781196 5.662362 3.711451 #> [2,] 11.004899 5.9308344 4.148042 1.624932 9.377803 7.683897 7.651135 #> [3,] 12.744279 7.6608220 5.468298 1.197705 11.002170 8.443905 9.208311 #> [4,] 3.147326 2.2163648 4.472013 8.972341 1.863860 4.085256 1.508009 #> [5,] 6.450196 2.4028933 1.855537 6.235591 4.671887 1.802845 2.999529 #> [6,] 5.426419 0.3076183 1.968690 6.540938 3.752238 3.191816 2.035433 #> [,16] [,17] [,18] [,19] [,20] #> [1,] 5.0249978 4.366832 6.115025 10.295145 9.329195 #> [2,] 5.7238929 10.111966 10.506006 5.847935 4.870746 #> [3,] 6.4236552 12.530022 11.943986 3.276116 2.428990 #> [4,] 4.6059128 3.687053 3.201102 11.211283 10.353320 #> [5,] 0.3700368 7.855135 5.363836 7.259799 6.521404 #> [6,] 2.5682880 5.778191 4.892205 8.746611 7.867663