Scott Chamberlain
2011-Apr-11 15:37 UTC
[R] Geographic distance between lat-long points in R?
Dear R, I have a bunch of geographic locations specified by lat-long coordinates. What's an easy way to calculate geographic distance between any two points? OR, perhaps there is a function for calculating a distance matrix for K sites? Sincerely, Scott Chamberlain [[alternative HTML version deleted]]
I found something here http://www.biostat.umn.edu/~sudiptob/Software/distonearth.R #The following program computes the distance on the surface of the earth between two points point1 and point2. Both the points are of the form (Longitude, Latitude) geodetic.distance <- function(point1, point2) { R <- 6371 p1rad <- point1 * pi/180 p2rad <- point2 * pi/180 d <- sin(p1rad[2])*sin(p2rad[2])+cos(p1rad[2])*cos(p2rad[2])*cos(abs(p1rad[1]-p2rad[1])) d <- acos(d) R*d } Dirk -- View this message in context: http://r.789695.n4.nabble.com/Geographic-distance-between-lat-long-points-in-R-tp3442338p3442355.html Sent from the R help mailing list archive at Nabble.com.
Eik Vettorazzi
2011-Apr-11 16:33 UTC
[R] Geographic distance between lat-long points in R?
Hi Scott, have a look at the 'earth.dist'-function in the package 'fossil'. hth. Am 11.04.2011 17:37, schrieb Scott Chamberlain:> Dear R, > > > I have a bunch of geographic locations specified by lat-long coordinates. What's an easy way to calculate geographic distance between any two points? OR, perhaps there is a function for calculating a distance matrix for K sites? > > > Sincerely, > Scott Chamberlain > > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.-- Eik Vettorazzi Institut f?r Medizinische Biometrie und Epidemiologie Universit?tsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790
Please allow me to present you the ultimate distance calculation algorithm by Charles Karney, accurate to one nanometre: http://geographiclib.sourceforge.net/cgi-bin/Geod -- View this message in context: http://r.789695.n4.nabble.com/Geographic-distance-between-lat-long-points-in-R-tp3442338p3466836.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]