[GIS] Approximate distance between two points (longitude / latitude) without Haversine

coordinatesdistancemapsr

How can I judge from the long/lat coordinates of a point A alone whether it is possibly/certainly not within a short distance of x meters from another coordinate B, using R (without applying geosphere::distHaversine or any other advanced calculation)?

"Certainly" in this case means that the long/lat of A tells me that it cannot be within the critical distance to B, while "possibly" means the complementary case.

Example:

x <- 100
point_A <- c("long"=8.678180,"lat"=50.114390)
point_B <- data.frame("id"=c(1,2,3,4),"long"=c(8.678459,8.618162,8.610878,7.208705),
"lat"=c(50.114124,50.226831,50.230530,50.799290))
point_B_certainly_not_in_distance <- subset(point_B, ...) # wanted
point_B_possibly_in_distance <- subset(point_B, ...) # wanted

In this example, only coordinate with id 1 should be identified as possibly within distance, whereas id 2, 3 and 4 should be identified as certainly not in distance.

To clarify the purpose: Imagine that point_B has >10^6 rows. In that case, a simplified "pre-subsetting" before applying the Haversine formula makes great sense.

Best Answer

1 degree of latitude is the same distance (1/360 circumference) everywhere on the globe, so you can cut on latitude difference. Two points that have a latitude difference of 1 degree can't be nearer than 1/360 of the circumference.

Having done that, you're left with points in a narrow latitude band, you could work out the radius of that band, approximate it as a circle, map the points to the circle (a sine and a cosine and a multiply or two), and then use the circle distance as a threshold, although points nearer the poles could have under-threshold great circle distances but over-threshold approximate latitude band distances. So the threshold may need some correction which would depend on latitude. Now its getting complex, and the benefit isn't clear.

Another method with a couple of sines and cosines would be to compute the 3d position of a point, then use Pythagoras to compute the straight-line Euclidean distance between points through the globe rather than the great circle distance. This distance will always be less than the surface distance, so if Euclidean distance > threshold then the great circle distance will be greater than the threshold. Drop the point.

In any event you don't need to compute the distance, which involves computing an arcsin (in the formula on Wikipedia), you only need compute the angle, which is a couple or so sines and cosines. Work out the angle threshold for your distance threshold and then you only do arcsin on the points in your threshold to get the distance.