How can I calculate the distance between two points (lon/lat) if any of the points exceeds the antimeridian (+-180 longitude)? Im 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. Is there a way to go about this problem? I have seen threads on similar problems but not using R.

Any pointers are highly appreciated, thanks!

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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