多边形遏制

Polygon containment

数据保存在 Postgres 数据库中(带有 PostGIS 扩展名)。我有一个 table,其中包含列:pid、geometry、parent。 pID 是主键,geometry 是用点描述的地理数据,parent 列包含该记录父项的 pID。 这意味着我们想要 table 这样的顺序:

我们面临的问题是如果我们不知道它们的初始顺序,如何找到 closest/smallest 父多边形。如果我们先处理 C,然后我们可以添加 D 作为父级,但是如果我们从 A 和 B 开始,D 不是正确的父级。

如果您有任何建议,如何解决这个问题,我将不胜感激。

使用带有地理区域的额外列,然后在您的查询中使用 containswithin&& 或其他包含操作。最后按此新列排序 desc 并限制 1 以获得父级

例如,一行必须是:

  • A, square(geometry),C,Area(100),BoundingBox(square)
  • B、方形(几何)、C、面积(100)、边界框(方形)
  • C,多边形(几何),D,面积(2000),边界框(多边形)

st_area 和 st_envelope 函数可以提供帮助

查询必须是

Select id 
from Table 
Where st_envelope('parameter') @ BoundingBox 
ORDER BY Area DESC 
LIMIT 1

形成 postgis 文档 http://postgis.net/docs/manual-2.3/ST_Geometry_Contained.html

@ — Returns TRUE if A's bounding box is contained by B's.

使用 @ 制作容器过滤器,因此您拥有所有包含几何图形的 'parents',然后获取其中一个(按区域排序)