rdist.earth {fields}R Documentation

Great circle distance matrix

Description

Given two sets of longitude/latitude locations computes the Great circle (geographic) distance matrix among all pairings.

Usage

rdist.earth(x1, x2, miles = TRUE, R = NULL)

Arguments

x1 Matrix of first set of lon/lat coordinates first column is the longitudes and second is the latitudes.
x2 Matrix of second set of lon/lat coordinates first column is the longitudes and second is the latitudes. If missing x1 is used.
miles If true distances are in statute miles if false distances in kilometers.
R Radius to use for sphere to find spherical distances. If NULL the radius is either in miles or kilometers depending on the values of the miles argument. If R=1 then distances are of course in radians.

Details

Surprisingly this all done efficiently in R by dot products of the direction cosines. Thanks to Qing Yang for pointing this out a long time ago.

Value

The great circle distance matrix if nrow(x1)=m and nrow( x2)=n then the returned matrix will be mXn.

See Also

rdist, stationary.cov

Examples

out<- rdist.earth ( ozone$lon.lat)
#out is a 20X20 distance matrix

[Package fields version 5.02 Index]