MySQL Forums
Forum List  »  GIS

Re: [help] distance function using the great-circle distance formula
Posted by:
Date: November 10, 2008 05:28AM

You were accepting POINT as arguments, and then calling geomFromText again, corrected version:

CREATE FUNCTION distance(a POINT, b POINT) RETURNS double
DETERMINISTIC
COMMENT 'Spatial distance function using the great-circle distance formula (in km)'
RETURN ( 6378
* acos(
sin( radians(X(a)) ) * sin( radians(X(b)) )
+ cos( radians(X(a)) ) * cos( radians(X(b)) )
* cos( radians(Y(b)) - radians(Y(a)) )
)
)

A simple optimisation would be to store x() and y() results of a and b too.

Options: ReplyQuote


Subject
Views
Written By
Posted
Re: [help] distance function using the great-circle distance formula
5090
November 10, 2008 05:28AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.