使用多边形或圆作为搜索来查找纬度/经度
我不适合这里,所以如果我没有正确/清楚地问这个问题,请原谅我。
我有一张用户表,每个用户都有纬度/经度。
我从联邦机构收到一个查询,该查询提供了一个多边形或一个圆形,如下所示:
<polygon>38.47,-120.14 38.34,-119.95 38.52,-119.74 38.62,-119.89 38.47,-120.14</polygon>
<circle>32.9525,-115.5527 0</circle>
给定这两个输入中的任何一个,我需要返回多边形或圆形内的所有用户。
我已经查看了所有内容,阅读了所有 mysql 空间文档等,我要么错过了一个步骤,要么只是没有理解查询方法。
任何帮助将不胜感激!
I'm out of my element here so please forgive me if I dont ask this correctly/clearly.
I have a table of users with lat/long for each one.
I get a query from a federal agency that provides either a polygon or a circle like this:
<polygon>38.47,-120.14 38.34,-119.95 38.52,-119.74 38.62,-119.89 38.47,-120.14</polygon>
<circle>32.9525,-115.5527 0</circle>
Given either of these two inputs, I need to return all users within the polygon or circle.
I've looked all over, read all the mysql spatial docs etc. and I am either missing a step or just not grokking the query method.
ANY help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你读过 http://howto-use-mysql-spatial-ext.blogspot.com /?
Have you read http://howto-use-mysql-spatial-ext.blogspot.com/ ?
这是我想出的答案,似乎正在工作:
首先,我通过添加一个字段来保存从用户纬度/经度创建的空间点来更改表:
从那里,我使用它来查询以查找多边形内的用户:
对于新用户,我创建了一个触发器来根据纬度/经度更新
位置
(如果没有纬度\经度,则无法添加用户):This is the answer that I came up with and appears to be working:
First, I altered the table by adding a field to hold the spatial points created from the users lat/lon:
From there, I'm using this to query to find the users within the polygon:
For new users I created a trigger to update the
location
from the lat/lon (user can't be added without a lat\lon):对于圆,您需要计算从圆中心到人员列表中每个纬度/经度的距离。如果距离小于圆的半径,则该人在圆内。计算沿着“大圆”的 2 个纬度/经度之间的距离的典型公式称为半正矢公式。下面的网站用 JavaScript 显示了这个公式。
http://www.movable-type.co.uk/scripts/latlong.html
对于一般的多边形来说,这要困难得多。对于多边形中的一般点,点包含测试似乎可以假设一个简单的等矩形投影(x = lon,y = lat)。
For a circle, you would need to compute the distance from the circle center to each of the lat/lon's in your persons list. If the distance is less than the radius of the circle, that person is inside the circle. Typical formula for computing distances between 2 lat/lon's along the 'great circle' is called the haversine formula. The website below shows this formula in javascript.
http://www.movable-type.co.uk/scripts/latlong.html
For a general polygon, this is much harder.For general point in a polygon, the Point Inclusion Test seems to work assuming a trivial Equirectanglular projection (x = lon, y = lat).