Learn R Programming

fields (version 6.8)

rdist.earth: 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

Value

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

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.

See Also

rdist, stationary.cov, fields.rdist.near

Examples

Run this code
data(ozone2)
out<- rdist.earth ( ozone2$lon.lat)
#out is a 153X153 distance matrix
upper<-  col(out)> row( out)
# histogram of all pairwise distances. 
hist( out[upper])

Run the code above in your browser using DataLab