Wednesday 29 March 2017

geometry - A reverse of Haversine formula for MySQL?




In my DB i store a center point, along with a radius (in meters).



I'm looking to pass in a lat/lng, and then have the mysql values i've stored create a circle to tell me if my point i passed in is within that circle. Is there something that would allow me to do this, similar to the haversine forumla (which would assume that my point was already in the db).



Haversine Formula:
( 3959 * acos( cos( radians(40) ) * cos( radians( lat ) ) * cos( radians( long ) - radians(-110) ) + sin( radians(40) ) * sin( radians( long ) ) )



db:



circleLatCenter, circleLngCenter, Radius




passing in>
select id from foo where lat,lng in (make circle function: circleLat, circleLng, radius)


Answer



MySQL has a whole host of spatial data functions:



Spatial Extensions to MySQL



I think the section on measuring the relationships between geometries is what you're after:




Relationships Between Geometries


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...