Description Usage Arguments Value Note Examples

Convert one or two rectangular objects containing lon-lat coordinates into vector or matrix of geodesic distances in metres.

1 2 3 4 5 6 7 8 |

`x` |
Rectangular object (matrix, |

`y` |
Optional second object which, if passed, results in distances
calculated between each object in |

`paired` |
If |

`sequential` |
If |

`pad` |
If |

`measure` |
One of "haversine" "vincenty", "geodesic", or "cheap" specifying desired method of geodesic distance calculation; see Notes. |

If only `x`

passed and `sequential = FALSE`

, a square
symmetric matrix containing distances between all items in `x`

; If only
`x`

passed and `sequential = TRUE`

, a vector of sequential
distances between rows of `x`

; otherwise if `y`

is passed, a matrix
of `nrow(x)`

rows and `nrow(y)`

columns. All return values are
distances in metres.

`measure = "cheap"`

denotes the mapbox cheap ruler
https://github.com/mapbox/cheap-ruler-cpp; `measure = "geodesic"`

denotes the very accurate geodesic methods given in Karney (2013)
"Algorithms for geodesics" J Geod 87:43-55, and as provided by the
codesf::st_dist() function.

1 2 3 4 5 6 7 8 9 10 | ```
n <- 50
# Default "cheap" distance measure is only accurate for short distances:
x <- cbind (runif (n, -0.1, 0.1), runif (n, -0.1, 0.1))
y <- cbind (runif (2 * n, -0.1, 0.1), runif (2 * n, -0.1, 0.1))
colnames (x) <- colnames (y) <- c ("x", "y")
d0 <- geodist (x) # A 50-by-50 matrix
d1 <- geodist (x, y) # A 50-by-100 matrix
d2 <- geodist (x, sequential = TRUE) # Vector of length 49
d2 <- geodist (x, sequential = TRUE, pad = TRUE) # Vector of length 50
d0_2 <- geodist (x, measure = "geodesic") # nanometre-accurate version of d0
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.