Mysql,如何找到矩形边界的交集
我已将来自谷歌地图的边界保存在我的数据库表中。现在我必须根据匹配边界来显示这些条目。
例如,我有一个基于位置/边界的仪表板条目表。我正在保存谷歌地图返回的每个仪表板条目的界限。现在,如果用户想查看与他的城市/国家/地区相关的仪表板帖子,那么我必须根据用户城市/国家/地区边界与仪表板条目边界进行匹配。因此,对于该用户,将显示其边界与用户城市/国家/地区边界重叠的所有仪表板条目。
现在我正在尝试使用 MySql OVERLAPS。但我无法获得正确的结果:(
转储带有一些测试条目的表:
INSERT INTO dashboard_entries
(id, category_id, entry_title, entry_description, customer_id, entry_date, latitude, longitude, bounds_ne_lat, bounds_ne_lng, bounds_sw_lat, bounds_sw_lng)
VALUES (150, 10, 'Blog Post for China Trip', 'Test Description', 43, '2012-02-08 15:17:46', '48.229147', '16.346052', 39.9084350, 78.6526391, 32.5301142, 116.3918633), (151, 16, 'Trip Post for Lahore Pakistan', 'Trip Post for Lahore Pakistan', 43, '2012-02-08 15:19:14', '48.229147', '16.346052', 34.0160320, 66.6578507, 24.7482340, 75.3818660);
这是我正在使用的查询:
select *
from dashboard_entries
where Overlaps(GeomFromText('Polygon((34.0160320 66.6578507,34.0160320 75.3818660,24.7482340 75.3818660,24.7482340 66.6578507,34.0160320 66.6578507))'), GeomFromText('Polygon((bounds_ne_lat bounds_ne_lng,bounds_ne_lat bounds_sw_lng,bounds_sw_lat bounds_sw_lng,bounds_sw_lat bounds_ne_lng,bounds_ne_lat bounds_ne_lng))'))
I have saved bounds in my database table coming from google maps. Now i have to show these entries based on matching the bounds.
For example, I have a table for dashboard entries that are based on locations/bounds. I am saving bounds against each dashboard entry that is returned by google maps. Now, if user wanted to see the dashboard posts that are related to his city/country then i have to do matching based on user city/country bounds with dashboard entries bounds. So for that user, all those dashboard entries will appear whose bounds overlaps with user city/country bounds.
Right now i am trying with MySql OVERLAPS. But I amm unable to get proper result :(
Dump of table with some test entries:
INSERT INTO dashboard_entries
(id, category_id, entry_title, entry_description, customer_id, entry_date, latitude, longitude, bounds_ne_lat, bounds_ne_lng, bounds_sw_lat, bounds_sw_lng)
VALUES (150, 10, 'Blog Post for China Trip', 'Test Description', 43, '2012-02-08 15:17:46', '48.229147', '16.346052', 39.9084350, 78.6526391, 32.5301142, 116.3918633), (151, 16, 'Trip Post for Lahore Pakistan', 'Trip Post for Lahore Pakistan', 43, '2012-02-08 15:19:14', '48.229147', '16.346052', 34.0160320, 66.6578507, 24.7482340, 75.3818660);
Here is the query that i am using:
select *
from dashboard_entries
where Overlaps(GeomFromText('Polygon((34.0160320 66.6578507,34.0160320 75.3818660,24.7482340 75.3818660,24.7482340 66.6578507,34.0160320 66.6578507))'), GeomFromText('Polygon((bounds_ne_lat bounds_ne_lng,bounds_ne_lat bounds_sw_lng,bounds_sw_lat bounds_sw_lng,bounds_sw_lat bounds_ne_lng,bounds_ne_lat bounds_ne_lng))'))
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我使用mysql的INTERSECT函数来查找两个矩形的交集。我相信重叠功能还没有实现。它需要两个矩形边界参数,如下所示。第二个参数也是保存在数据库中的多边形。
I have used INTERSECT function of mysql to find the intersection on two rectangles. I believe Overlaps function is not implemented yet. It takes two rectangular bounds params as shown below. Second parameter is also a polygon that is saved in database.