1

I'm trying to calculate the shortest distance between a line (described as a pair of [lat, long]s) and a point (lat, long) accurately. I've read many Wikipedia pages, but I'm new to the topic. I've read this question, but I'm still confused, because they say that

Literally, a "straight line" will pass beneath the earth's surface.

while my line lies on the surface of the Earth. How can I calculate this?

2
  • What software are you using?
    – Maksim
    Commented Sep 24, 2014 at 14:09
  • I'm not using any software, just need this calculation in a project. (A Java project, if it matters.) Commented Sep 24, 2014 at 14:11

1 Answer 1

1

If you know postgis, you can create the shortest line between two geometries : http://postgis.net/docs/manual-2.1/ST_ShortestLine.html. Then you can calculate the length with :http://postgis.net/docs/manual-2.1/ST_Length.html

If you dont need to create the line : st_distance should be enough : http://postgis.net/docs/manual-2.1/ST_Distance.html

2
  • I'd rather like to compute it by myself, without Postgis. But thanks, anyway! Commented Sep 24, 2014 at 14:09
  • 1
    My solution is given in sourceforge.net/p/geographiclib/discussion/1026621/thread/… this uses C++. However the solution can be implemented in Java too, since the needed functions are in the Java version of GeographicLib
    – cffk
    Commented Sep 24, 2014 at 21:58

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