On Thu, 14 Jan 2010, ONKELINX, Thierry wrote:

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.

From the code of rdist.earth(), it is using a sphere with a 6378388m
parameter (which is like the International 1909 ellipsoid, but a sphere). geod.dist() is using WGS84 a=6378137.0 rf=298.257223563:

http://code.google.com/p/r-oce/source/browse/trunk/R/misc.R

near line 280. The code under spDistsN1() uses WGS84 values, but with the radius in km:

http://r-spatial.cvs.sourceforge.net/viewvc/r-spatial/sp/src/gcdist.c?revision=1.6&view=markup

So in principle geod.dist() and spDistsN1(..., longlat=TRUE) should yield equivalent results, because their assumptions are the same.

Several of the references suggest that the geographic pole should not be input. It looks as though the oce implementation handles this more gracefully than sp.

Hope this helps,

Roger


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.onkel...@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-boun...@stat.math.ethz.ch
[mailto:r-sig-geo-boun...@stat.math.ethz.ch] Namens Karl Ove Hufthammer
Verzonden: donderdag 14 januari 2010 10:57
Aan: r-sig-geo@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 <k...@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@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.

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


--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no

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

Reply via email to