[英]Is there ST_Intersects alternative that allows two(or more) polygons to share sides
I am using ST_Intersects to check if two polygons intersect.我正在使用 ST_Intersects 检查两个多边形是否相交。 Relevant part of my query is:
我查询的相关部分是:
SELECT entity_number
FROM coordinates
WHERE ST_INTERSECTS($1, location)
It works well to determine if one polygon crosses the other's surface:它可以很好地确定一个多边形是否与另一个多边形的表面相交:
I expected ST_Intersects to return false when two polygons share sides, but it does not:当两个多边形共享边时,我希望 ST_Intersects 返回 false,但它不会:
I read about other methods like ST_Covers, ST_Contains, ST_ContainsProperly, ST_Within,ST_DWithin
.我阅读了其他方法,例如
ST_Covers, ST_Contains, ST_ContainsProperly, ST_Within,ST_DWithin
。 But i am not sure which one suits my needs.但我不确定哪一个适合我的需要。
Is there any method that allows two polygons to share sides?有什么方法可以让两个多边形共享边吗?
You want ST_Overlaps
:你想要
ST_Overlaps
:
Returns TRUE if geometry A and B "spatially overlap".
如果几何 A 和 B“空间重叠”,则返回 TRUE。 Two geometries overlap if they have the same dimension, each has at least one point not shared by the other (or equivalently neither covers the other), and the intersection of their interiors has the same dimension.
如果两个几何具有相同的维度,则它们重叠,每个几何至少有一个点不被另一个共享(或者等效地不覆盖另一个),并且它们内部的交集具有相同的维度。 The overlaps relationship is symmetrical.
重叠关系是对称的。
As pointed out by Laurenz, ST_Overlaps
is what you're looking for.正如 Laurenz 所指出的,
ST_Overlaps
就是您要找的。 However, quite often it does not suffice to simply check if polygons do overlap, but also "how much" they overlap.然而,通常仅仅检查多边形是否重叠是不够的,还要检查它们重叠“多少”。 In other words, how much of geometry a overlaps with geometry b ?
换句话说,有多少几何 a与几何 b重叠?
ST_Intersection
returns a polygon that is the result of the intersection of two geometries, so you can ST_Area
this generated polygon and compare it with one of the polygons given to the function, eg given these polygons.. ST_Intersection
返回一个多边形,它是两个几何图形相交的结果,因此您可以ST_Area
这个生成的多边形并将其与给定的多边形之一进行比较 function,例如给定这些多边形..
... this would be the result of ST_Intersection
...这将是
ST_Intersection
的结果
And this is how you could calculate the percentage of the overlap这就是你如何计算重叠的百分比
SELECT
ST_Area(ST_Intersection(g1,g2))/ST_Area(g1)*100 AS perc_g1_overlap,
ST_Intersection(g1,g2)
FROM t;
perc_g1_overlap | st_intersection
--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
16.555309365086124 | 0103000020E6100000010000000500000054435ACF861E12C02068AC4B11214B4054435ACFD60A12C02068AC4B11214B4054435ACFD60A12C04B266CCD791F4B4054435ACF861E12C04B266CCD791F4B4054435ACF861E12C02068AC4B11214B40
(1 row)
Demo: db<>fiddle
演示:
db<>fiddle
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.