我将如何编写这个空间查询?
我有以下表结构:
column names : cell longitude latitude bcch bsic data types : varchar double double double double Keys : x
所有小区
- 我想知道彼此 10 公里范围内且
- 具有相同 bcch+bsic 的
。 满足上述要求的空间sql查询是什么?
由于我对postgis的理解有限,请随意以“使用此数据库表结构代替”开始你的答案,以便它更面向GIS(我相信存在点的概念而不是纬度/经度列)。我以前没有写过空间查询,正在考虑购买“PostGIS In Action”一书,但需要知道我想做的事情是否可行以及如何实现。
另外我想提一下,我知道如何在标准 sql 中做到这一点。我需要一个空间查询,因为大约有 10000 条记录,并且使用标准 sql 方法,我需要生成 10000*10000(每个单元格的所有其他单元格)记录,然后查询它们,这将是非常低效的。
I have the following table structure:
column names : cell longitude latitude bcch bsic data types : varchar double double double double Keys : x
I want to know all the cells which are
- in 10 km range of each other AND
- have the same bcch+bsic.
What would be the spatial sql query for the above requirement?
Due to my limited understanding of postgis feel free to start your answer with "use this database table structure instead" so that it is more GIS oriented (I believe there is a concept of points rather than lat/long colums). I haven't written spatial queries before and am considering buying the "PostGIS In Action" book but need to know if what I am trying to do is possible and how.
Additionally I would like mention that I know how to do it in standard sql. I need a spatial query because there are round about 10000 records and using a standard sql method I would need to generate 10000*10000 (all the other cells for each cell) records and then query them which would be highly inefficient.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
丹尼斯,
那不是真的。要点索引在这里会有所帮助。
Basarat 我不太清楚你期望什么输出。这是针对每个单元格的查询
将返回 10 公里范围内的那些。首先,您要添加一个地理列,然后为其创建一个要点索引。 《PostGIS 实践》第一章对此进行了介绍。
假设您有一个名为 geog 的新列,您已在其中添加了要点索引。
那么你的查询将是
如果你不希望输出为数组 - 你可以这样做
Denis,
that is not true. A gist index would help here.
Basarat I'm not quite clear what output you expect. Here is a query that for each cell
would return those at that are within 10km. First you want to add a geography column and then create a gist index of it. That's covered in first chapter of PostGIS in Action.
So lets say you have this new column called geog that you have put a gist index on.
Then your query would be
If you don't want the output as an array -- you can do