[R-sig-Geo] Best way to calculate distance between geographicalpoints

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Jan 14 11:55:06 CET 2010


Dear Karl,

I think that the relative errors are more relevant than absolute errors.
The relative error on the equatorial circumference for "geo.dist" is
0.33%, which is not that accurate. The relative error on the meridional
distance is only about 0.085%, which should accurant enough for most
applications.

Just my 2 eurocents.

Thierry


------------------------------------------------------------------------
----
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
Thierry.Onkelinx at inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of
data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-sig-geo-bounces at stat.math.ethz.ch
[mailto:r-sig-geo-bounces at stat.math.ethz.ch] Namens Karl Ove Hufthammer
Verzonden: donderdag 14 januari 2010 10:57
Aan: r-sig-geo at stat.math.ethz.ch
Onderwerp: Re: [R-sig-Geo] Best way to calculate distance between
geographicalpoints

On Thu, 14 Jan 2010 10:27:17 +0100 Karl Ove Hufthammer <karl at huftis.org>
wrote:
> I have found three functions for calculating the distance between 
> geographical points, 'geo.dist' in the 'oce' package, 'rdist.earth' in

> the 'fields' package, and 'spDistsN1' in the 'sp' package. They all 
> give slightly difference answers, so my question is: which of them is 
> best, i.e., gives the most accurate answer?

One simple test would be to calculate the circumference of the earth at
the equator and the meridian. But this test gives conflicting answers.

According to Wikipedia, "http://en.wikipedia.org/wiki/Earth" the
equatorial circumference is 40075.02 km and the meridional circumference
is 40007.86 km.

When calculating half the equatorial circumference, 'spDistsN1' is best,
and gives the *exact* answer, while 'rdist.earth' is close (less than
one km difference), and 'geo.dist' is far from the correct answer
(133.92 km difference). So it would initially seem that 'spDistsN1' is
the one to use, and one should avoid 'geo.dist'.

But when calculating the meridional distance, 'geo.dist' gives the exact
answer, while both 'rdist.earth' and 'spDistsN1' are both off by about
34 km (but in difference directions).

So which to use is still an open question ...

Here is the code I used:

library(oce)
library(fields)
library(sp)

# Equatorial
lt1=0
lt2=0
lg1=0
lg2=180

a=matrix(c(lg1,lt1),nrow=1)
b=matrix(c(lg2,lt2),nrow=1)

# Calculated distance
geod.dist(lt1,lg1,lt2,lg2)
rdist.earth(a,b, miles=FALSE)
spDistsN1(a,b, longlat=TRUE)

# Correct distance (according to Wikipedia)
40075.02/2


# Meridional
lt1=-90
lt2=90
lg1=0
lg2=0

a=matrix(c(lg1,lt1),nrow=1)
b=matrix(c(lg2,lt2),nrow=1)

# Calculated distance
geod.dist(lt1,lg1,lt2,lg2)
rdist.earth(a,b, miles=FALSE)
spDistsN1(a,b, longlat=TRUE)

# Correct distance (according to Wikipedia)
40007.86/2 

--
Karl Ove Hufthammer

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.



More information about the R-sig-Geo mailing list