Friday, 8 September 2017

How to calculate distance between two locations using stored procedure in MySQL?


I have a database with locations with their lat and long coordinates. The area of locations is quite small with lots of them quite near each other.


I'm using this stored procedure in my project. http://www.artfulsoftware.com/infotree/queries.php?&bw=1680#109


I'm having troubles with accuracy. I need it to return more accurate results (in metres) instead of just 0 distance.


Can it be modified so I get better results?



Answer



If the distances are so close together that single precision floats can't capture the distance, you probably don't need to account for the curvature of the earth at all — you must be dealing with phenomena only a few meters apart. The simplest solution is to then use double precision, as Rowland mentioned, or easier yet, just compute a linear distance between the two points, ignoring earth curvature.


In the highly unlikely event that you do in fact have high-precision, high-accuracy data, you can use the Vincenty's formula, which can give accurate results down to millimeters.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...