Question

enter image description here

Suppose I have a line AB as MULTIPOINT(52.3641917981 4.87673850395, 52.3821782019 4.90619949605) and a point P as POINT(51.3641917981 2.87673850395) in MYSQL. I want to calculate the shortest distance D between point P and line AB. Please help me regarding this problem.

Thanks in advance.

Was it helpful?

Solution

I'm sure MySQL has the ST_Distance method for ordering by the distance?

order by st_distance(geom1, geom2)

And for calculating the distance, you can reference this blog:

MySqlPerformanceBlog

It shows how to define a user function (haversine) for making the calculations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top