gcd.slc(ss, radius = 6371)
gcd.hf(ss, radius = 6371)
gcd.vife(ss, a = 6378137, b = 6356752.314245, f = 1/298.257223563)
dist
for details) that
contains the distances (in km) between the locations (rows of
ss
).dist
. The great circle distance is appropriate when the
sampling points are located on a spheroid (e.g. planet
Earth). Function gcd.slc
uses the spherical law of cosines,
which is the fastest of the three approaches and performs relatively
well for distances above 1 m. Function gcd.hf
uses the the
Haversine formula, which is more accurate for smaller distances
(bellow 1 m). Finally, functions gcd.vife
uses the Vincenty
inverse formula for ellipsoids, which is an iterative approach that
take substantially more computation time than the latter two methods
has precision up to 0.5 mm with exact longitudes and lattitudes.Vincenty, T. (1975) Closed formulas for the direct and reverse geodetic problems. J. Geodesy 51(3): 241-342
eigenmap-class
#
# Calculating the distances between Canada's capital cities:
CapitalCitiesOfCanada <-
matrix(c(45.417,-75.7,53.533333,-113.5,48.422151,-123.3657,
49.899444,-97.139167,45.95,-66.666667,47.5675,-52.707222,
44.647778,-63.571389,43.7,-79.4,46.24,-63.1399,
46.816667,-71.216667,50.454722,-104.606667,62.442222,-114.3975,
63.748611,-68.519722,60.716667,-135.05),14L,2L,byrow=TRUE,
dimnames=list(c("Ottawa","Edmonton","Victoria","Winnipeg",
"Fredericton","St-John's","Halifax","Toronto",
"Charlottetown","Quebec City","Regina",
"Yellowknife","Iqaluit","Whitehorse"),c("Lon","Lat")))
#
sphericalcosdists <- gcd.slc(CapitalCitiesOfCanada)
vincentydists <- gcd.vife(CapitalCitiesOfCanada)
#
cor(as.numeric(sphericalcosdists),as.numeric(vincentydists))
percentdev <- 100*(vincentydists-sphericalcosdists)/vincentydists
mean(percentdev)
# Spherical Law of Cosines underestimated these distances by ~0.26
# percent.
#
Run the code above in your browser using DataLab