Learn R Programming

REAT (version 1.3.1)

dist.mat:

Description

Calculation of an euclidean distance matrix between points with stated coordinates (lat, lon)

Usage

dist.mat(startpoints, sp_id, lat_start, lon_start, endpoints, ep_id, 
lat_end, lon_end, unit = "km")

Arguments

startpoints
A data frame containing the start points
sp_id
Column containing the IDs of the startpoints in the data frame startpoints
lat_start
Column containing the latitudes of the start points in the data frame startpoints
lon_start
Column containing the longitudes of the start points in the data frame startpoints
endpoints
A data frame containing the end points
ep_id
Column containing the IDs of the endpoints in the data frame endpoints
lat_end
Column containing the latitudes of the end points in the data frame endpoints
lon_end
Column containing the longitudes of the end points in the data frame endpoints
unit
Unit of the resulting distance: unit="m" for meters, unit="km" for kilometers or unit="miles" for miles

Value

The function returns a data.frame containing 4 columns: The start point IDs (from), the end point IDs (to), the combination of both (from_to) and the calculated distance (distance).

Details

The function calculates an euclidean distance matrix between points with stated coordinates (lat and lon). While \(m\) start points and \(n\) end points are given, the output is a linear \(m * n\) distance matrix.

References

de Lange, N. (2013): “Geoinformatik in Theorie und Praxis”. 3rd edition. Berlin : Springer Spektrum. Krider, R. E./Putler, R. S. (2013): “Which Birds of a Feather Flock Together? Clustering and Avoidance Patterns of Similar Retail Outlets”. In: Geographical Analysis, 45, 2, p. 123-149

See Also

dist, dist.buf

Examples

Run this code
# Distances between geocoded pharmacies:
data(health1)
# Health service locations (physicians and pharmacies)
pharmacy <- health1[health1$type=="pharm",]
# Only pharmacies
pharmdistmat <- dist.mat (pharmacy[1:10,], "location", "lat", "lon", 
pharmacy, "location", "lat", "lon")
# Distance matrix for the first 10 pharmacy locations

Run the code above in your browser using DataLab