Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R calculating distance between 2 points on earth using package geosphere [closed]

My question is based upon this question. Using it I wrote below code where first set of coordinates are for LGA airport NY while second set of coordinates are for EWR airport NY. I get the answer 33713. Is that in miles or in kilometers? A quick google check says that the distance should be 33 miles (but it is not a straigh line/arc distance :( It is a distance by road). The package documentation says that the answers are in meters. Please clarify. Is this a good method to find the distance on Earth given 2 coordinates? How can I get answer in Miles?

library(geosphere)
distm (c(40.777250, -73.872610), c(40.6895, -74.1745), fun = distHaversine)
         [,1]
[1,] 33713.61
like image 943
user2543622 Avatar asked May 25 '16 18:05

user2543622


1 Answers

Yes, it's giving you the answer in meters. To convert to miles:

> distm(c(40.777250, -73.872610), c(40.6895, -74.1745), fun = distHaversine)[,1] / 1609
[1] 20.95315

20.95 miles as the crow flies.

like image 167
Edward R. Mazurek Avatar answered Oct 14 '22 10:10

Edward R. Mazurek