Learn R Programming

TDLM (version 1.1.1)

extract_distances: Compute the distance between pairs of locations

Description

This function computes the distance between pairs of locations based on geographical coordinates.

Usage

extract_distances(
  coords,
  method = "Haversine",
  id = NULL,
  show_progress = FALSE
)

Value

A square matrix representing the distance (in kilometers) between locations.

Arguments

coords

A two-column matrix or data.frame where each row represents the coordinates of a location (see Details).

method

A character string indicating which method to choose to compute the distances (see Details). Available options are "Haversine" or "Euclidean".

id

A vector with length equal to the number of locations, used as row names and column names for the output distance matrix (optional, NULL by default).

show_progress

A boolean indicating whether a progress bar should be displayed.

Author

Maxime Lenormand (maxime.lenormand@inrae.fr)

Details

coords must contain two columns: the first one for the longitude or "X" coordinates, and the second one for the latitude or "Y" coordinates. The "Haversine" method is used to compute great-circle distances from longitude/latitude, while the "Euclidean" method should be used for "X/Y" coordinates.

See Also

Associated functions: extract_opportunities()

Examples

Run this code
data(coords)

distance <- extract_distances(coords = coords, 
                              method = "Haversine",
                              id = rownames(coords))

Run the code above in your browser using DataLab