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?

Aron Lorincz
  • 111
  • 5

1 Answers1

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

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