Skip to content
Prev 77221 / 398502 Next

Converting coordinates to actual distances

On Wed, 14 Sep 2005, Paul Brewin wrote:

            
Using C code in the sp package (which will be exposed at the R level 
shortly) and sp > 0.8 and maptools > 0.5:
Loading required package: foreign
Loading required package: sp
# ll is a matrix of long-lat centroids of North Carolina county polygons
num [1:100, 1:2] -81.5 -81.1 -79.3 -79.8 -78.7 ...
+ lonlat)[[6]]

gives a full matrix measured in kilometers for the WGS-84 ellipsoid. 
Accessing the C function like this puts the responsibility for checking 
the argument modes on the user.

If this seems scary, rdist.earth() in the fields package has an R version 
of this. But maybe you need the actual functions to use great circle 
distance instead of Euclidean, rather than just to generate a distance 
matrix?

Hope this helps,

Roger Bivand