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.

put on hold as off-topic by PolyGeo 2 days ago

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "When seeking help to debug/write/improve code always provide the desired behavior, a specific problem/error and the shortest code (as formatted text, not pictures) needed to reproduce it in the question body. Providing a clear problem statement and a code attempt helps others to help you." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 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 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 9 '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 9 '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 9 '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 1 at 12:05

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

# 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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.