1

How can I calculate the distance between two points (lon/lat) if any of the points exceeds the antimeridian (+-180 longitude)?

I am using the distVincentyEllipsoid {geosphere} to calculate the shortest distance between two points. But if any of the points crosses the antimeridian the distance will be very close to zero.

I have seen Intersection algorithm that correctly handles the 180° meridian and poles? but it does not use R.

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
jO.
  • 361
  • 4
  • 16
  • You do not seem to be asking about distance at all, but rather about computing reasonable bounding boxes (aka extents) of data. Is that the case? If so, your question may already have been answered at http://gis.stackexchange.com/questions/17788. If not, please edit your question to make clear what you would expect to see in an answer. – whuber Apr 09 '14 at 16:01
  • Thanks for the comment. You're right, I was vague trying to squeeze in two different questions. I've updated it hopefully making it more focused. – jO. Apr 09 '14 at 16:19
  • There are many threads on this site about calculating distances on spheres and ellipsoids: AFAIK, they all work fine for longitudes beyond the [-180, 180] interval because they all use the sines and cosines of the latitudes. On that basis I doubt distVincentyEllipsoid is incorrect. Could you perhaps supply an example of a pair of points with its output and what you think is the correct distance? – whuber Apr 09 '14 at 17:06
  • simple workaround: shift all points in longitude so that your point of interest is at longitude 0. This will not modify the distances and none of the smallest distance will cross the antimeridian – radouxju Jul 01 '19 at 12:05

1 Answers1

2

There does not seem to be any limitations measuring across the antimeridian with this library:

library(geosphere)
# small distance across the antimeridian
distVincentyEllipsoid(c(-179.999, 0), c(179.999, 0))  # 222.639
# this should be zero, but tiny errors have entered in the maths
distVincentyEllipsoid(c(-180, 0), c(180, 0)) # 1.556904e-09

And if you have any longitudes outside [-180, 180], they will need to be normalised by adding/removing by a 360 phase.

Mike T
  • 42,095
  • 10
  • 126
  • 187