Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function to calculate geospatial distance between two points (lat,long) using R [duplicate]

I have geocoded points in long, lat format, and I want to calculate the distance between them using R. This seems pretty straight forward, yet I can't find a function that will do it easily. I've been attempting to do it with the gdistance package, but it seems very convoluted and oriented to graphing, I just need a number. Something like distanceBetween(pointA,pointB) that returns a number.

like image 384
SteveO7 Avatar asked Sep 02 '15 22:09

SteveO7


People also ask

How do you find the distance between lat and long points?

For this divide the values of longitude and latitude of both the points by 180/pi. The value of pi is 22/7. The value of 180/pi is approximately 57.29577951. If we want to calculate the distance between two places in miles, use the value 3, 963, which is the radius of Earth.

How do you find the distance between two lat long react natives?

type UseDistanceTypes = { from: { latitude: number; longitude: number }; to: { latitude: number; longitude: number }; }; const earthRadius = 6378137; const toRadius = (value: number): number => (value * Math. PI) / 180; export const useDistance = ({ from, to }: UseDistanceTypes): number => { const distance = Math.


1 Answers

Loading the geosphere package you can use a number of different functions

library(geosphere) distm(c(lon1, lat1), c(lon2, lat2), fun = distHaversine) 

Also:

distHaversine() distMeeus() distRhumb() distVincentyEllipsoid() distVincentySphere() 

...

like image 59
PereG Avatar answered Oct 15 '22 01:10

PereG