MySQL 的半正矢公式的逆运算?
在我的数据库中,我存储一个中心点以及半径(以米为单位)。
我希望传递 lat/lng,然后让我存储的 mysql 值创建一个圆圈,告诉我我传入的点是否在该圆圈内。 有没有什么东西可以让我这样做,类似于半正弦论坛(假设我的观点已经在数据库中)。
半正矢公式: ( 3959 * acos( cos( 弧度(40) ) * cos( 弧度( 纬度 ) ) * cos( 弧度( 长
) - 弧度(-110) ) + sin( 弧度(40) ) * sin( radians( long
) ) )
db:
circleLatCenter,circleLngCenter,
传入的半径> select id from foo where lat,lng in (制作圆函数:circleLat、circleLng、radius)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MySQL 拥有一整套空间数据函数:
MySQL 的空间扩展
我认为关于测量几何图形之间关系的部分就是您所追求的:
几何图形之间的关系
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
我通过大圆距离计算边界框并查询数据库来完成类似的地理搜索。 您仍然需要在应用程序中进行另一次处理,以从边界框到圆圈“圆角”。
因此,给定一个点数据库、一个搜索点 (X,Y) 和一个距离 D,找到 (X,Y) D 内的所有点:
作为捷径,我通常计算纬度和经度的每英里度数(在赤道,因为经度的每英里度数在两极不同),并将 deltaX 和 deltaY 导出为 (D * 度数) -纬度每英里)或度数经度每英里。 赤道与极点的差异并不重要,因为我已经在 SQL 查询后计算实际距离。
仅供参考 - 每英里 0.167469 至 0.014564 度经度,以及每英里 0.014483 度纬度
I've done similar geographical searches by computing the bounding box via great circle distance and querying the database for that. You still need another pass in your application to "round the corners" from bounding box to circle.
So, given a database of points, a search point (X,Y) and a distance D, find all points within D of (X,Y):
As a short-cut, I typically calculate degrees-per-mile for both lat and lon (at the equator, since the degrees-per-mile is different at the poles for lon), and derive deltaX and deltaY as (D * degrees-lat-per-mile) or degrees-lon-per-mile. The difference at the equator vs pole doesn't matter much, since I'm already computing actual distance after the SQL query.
FYI - 0.167469 to 0.014564 degrees-lon-per-mile, and 0.014483 degrees-lat-per-mile
我知道这是一篇早已死亡的帖子,但是,如果有人遇到过这种情况,您根本不需要创建“反向半正弦公式”。 半正矢公式给出了 a 点和 b 点之间的距离。 您需要 b 点和 a 点之间的距离进行计算。 这些是相同的值。
I know this is a long-dead post, but, in case anyone ever comes across this, you don't need to create a "reverse haversine formula" at all. The Haversine formula gives the distance between point a and point b. You need the distance between point b and point a, for your calculation. These are the same value.