查找与点相交的所有区域,反之亦然 - PostGIS
我正在开发一个使用 PostGIS 来保存空间数据的项目,其中有保存几何点数据的记录和保存几何区域数据的记录。为了解决我的问题,我正在寻找两个可以采用地理形状而不是几何形状作为参数的查询。
对于查询 AI 需要它返回与给定区域相交的所有点。
对于查询 BI 需要它返回与给定点相交的所有区域。
I'm developing a project using PostGIS to hold spatial data where I have records that hold geometry point data and records that hold geometry area data. To solve my problem I'm looking for two queries that can take geographic shapes rather than geometric shapes as parameters.
For query A I need it to return all points that intersect with a given area.
For query B I need it to return all areas that intersect with a given point.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
无论您走向哪个方向,查询都几乎相同,它仅取决于您的选择标准,假设您有下表:
使用以下内容:
或
将按原样显示该表(后者将提供更英语可读的输出)
现在,如果您也有一个类似的表,但您有点而不是几何图形中的多边形,要对它们进行交叉过滤,您可以使用简单的连接。
EG:
这将返回点表中落在代表您感兴趣的区域的所选多边形内的所有点。
注意:我在这里使用 ST_Within,但 PostGIS 中可能还有其他几何运算符可以执行许多其他类型的检查这将使您的相交和/或边界测量更加准确,但对于所有这些,原理都是相同的。
对于您的第二个查询,所需的 GIS-SQL 将非常相似,但您不需要返回给定多边形的点,而是需要反转您的条件以返回给定点的多边形:
注意:我们将参数保留在 ' ST_Within 的顺序完全相同,因为 ST_Within 使用以下规则进行处理:
由于该点仍然是两个实体中较小的一个,因此我们仍然需要检查相同的空间顺序。
The query is pretty much the same which ever direction you go, it just depends on your select criteria, lets assume you have the following table:
using the following:
or
will display that table as is (The later will give a more English readable output)
now if you also have a similar table, but instead of polygons in the geometry, you have points, to do cross filters on them you can use simple joins.
EG:
this will return all points from the points table that fall inside the selected polygon representing the area your interested in.
note: I'm using ST_Within here, but there are may other geometry operators in PostGIS that can do many other types of checking that would make your intersects and or bounding measurements more accurate, for all of them the principle however is the same.
For your second Query, the GIS-SQL needed is going to be very similar, but instead of returning the points for a given poly, you need to reverse your criteria to return polys for a given point:
NOTE: we keep the parameters in 'ST_Within in exactly the same order, because ST_Within processes using the following rule:
Since the point is still the smaller of the 2 entities then we still need to check for the same spatial ordering.