我的问题是:我有1000个包裹,其中1个是我的,我要做的是找到哪些是我的邻居,这意味着谁的包裹与我的包裹接触。一个完美的例子是在我发给你的图片上显示的。红色矩形是我的包裹,黑色矩形是我的邻居。我要做的是找到他们是谁。我创建了2个表,第一个表(parcels)包含不包含我的所有宗地,第二个表(Myparticle)仅包含我的宗地。作为空间数据,我拥有所有宗地的几何(列geom)和宗地数量。My parcel is red color and neighbourhood parcels are black
我正在尝试解决一个问题,我已经尝试了几天来解决它,但没有结果!所以最终的结果是,我想知道哪些包裹与我的包裹接触。我已经创建了2个表,这是我的代码,这是不工作
从kultura5_maxsip1 k、kultura5_maxsip s中选择st_touches(k.几何体,s.几何体)
2条答案
按热度按时间tjvv9vkg1#
ST_Touches()
可能不会返回太多结果,因为通常几何图形会自然地移动,除非您将它们ST_Snap()
在一起,或者应用统一的ST_SnapToGrid()
。此外,对“touch”的直观理解在这里是误导性的,因为如果一个形状的结束位置正好是另一个形状的开始位置,ST_Touches()
将返回True
。如果一个完全在另一个里面,它们也不被认为接触。阅读DE-9 IM的相关内容或浏览PostGIS文档以了解哪些函数查找哪些类型的空间关系是很好的选择。您可以轻松地测试所有这些函数,使用
ST_GeomFromText()
构建非常简单的形状,然后使用ST_AsText()
或QGIS检查它们。Demo:您可以在EPSG.io上阅读有关SRIDs的内容。请务必记住,它们不仅定义了目标区域限制,还定义了测量单位。如果您使用全局4326,然后测量ST_Distance(),它的单位是度,而不是米。如果你使用21781,你不能用一些缓冲区来编码瑞士以外的坐标。也有以英里/英尺为单位的系统。
这些包裹将在
ST_Touches()
意义上接触,因为它们重复使用相同的、完全圆形的坐标。现实生活中的数据通常来自于次优条件下容易出错的测量。只要它们移动了一点,就不再“接触”:
但是,如果你问现在哪些是相交的(有 * 任何 * 空间关系)或在一定距离内(你会认为足够近,同意他们在口语意义上接触):
你可以阅读Hausdorff distance,它更好地告诉你 * 整个 * 形状之间的距离有多近,而不仅仅是它们之间的最短捷径有多长。
ST_DWithin()
是True
,它基于形状之间的最小距离(最短捷径)是否低于限制。brccelvz2#
您可以尝试在此用例中使用DBScan(implemented in PostGIS)来确定相邻集群。
cluster_id
代表数据列所属的丛集。如果epsilon
值为0,函数只会依交集丛集。如果您的多边形不相交,您可以使用较小的值缓冲它们。