名称

ST_Overlaps — 测试两个几何是否具有相同的维度并相交,但每个几何至少有一个点不在另一个几何中

语法

boolean ST_Overlaps(geometry A, geometry B);

描述

如果几何 A 和 B “空间重叠”,则返回 TRUE。如果两个几何具有相同的维度,则它们在该维度中相交,并且每个几何至少有一个点在另一个几何内部(或等效地,没有一个几何覆盖另一个几何),则这两个几何重叠。重叠关系是对称的和自反的。

用数学术语来说:ST_Overlaps(A, B) ⇔ ( dim(A) = dim(B) = dim( Int(A) ⋂ Int(B) )) ∧ (A ⋂ B ≠ A) ∧ (A ⋂ B ≠ B)

[Note]

此函数自动包含一个边界框比较,该比较使用几何上可用的任何空间索引。

若要避免使用索引,请使用函数 _ST_Overlaps

由 GEOS 模块执行

[Important]

增强:3.0.0 启用对 GEOMETRYCOLLECTION 的支持

注意:这是返回布尔值(而非整数)的“允许”版本。

此方法实现了 OGC 简单要素 SQL 1.1 实施规范

s2.1.1.2 // s2.1.13.3

此方法实现了 SQL/MM 规范。

SQL-MM 3: 5.1.32

示例

ST_Overlaps 在以下情况下返回 TRUE

MULTIPOINT / MULTIPOINT

LINESTRING / LINESTRING

POLYGON / POLYGON

线段上的一个点被包含,但由于它具有较低的维度,因此它不会重叠或交叉。

SELECT ST_Overlaps(a,b) AS overlaps,       ST_Crosses(a,b) AS crosses,
       ST_Intersects(a, b) AS intersects,  ST_Contains(b,a) AS b_contains_a
FROM (SELECT ST_GeomFromText('POINT (100 100)') As a,
             ST_GeomFromText('LINESTRING (30 50, 40 160, 160 40, 180 160)')  AS b) AS t

overlaps | crosses | intersects | b_contains_a
---------+----------------------+--------------
f        | f       | t          | t

部分覆盖多边形的线段相交并交叉,但由于它具有不同的维度,因此不会重叠。

SELECT ST_Overlaps(a,b) AS overlaps,        ST_Crosses(a,b) AS crosses,
       ST_Intersects(a, b) AS intersects,   ST_Contains(a,b) AS contains
FROM (SELECT ST_GeomFromText('POLYGON ((40 170, 90 30, 180 100, 40 170))') AS a,
             ST_GeomFromText('LINESTRING(10 10, 190 190)') AS b) AS t;

 overlap | crosses | intersects | contains
---------+---------+------------+--------------
 f       | t       | t          | f

两个相交但没有一个被另一个包含的多边形重叠,但不会交叉,因为它们的交集具有相同的维度。

SELECT ST_Overlaps(a,b) AS overlaps,       ST_Crosses(a,b) AS crosses,
       ST_Intersects(a, b) AS intersects,  ST_Contains(b, a) AS b_contains_a,
       ST_Dimension(a) AS dim_a, ST_Dimension(b) AS dim_b,
       ST_Dimension(ST_Intersection(a,b)) AS dim_int
FROM (SELECT ST_GeomFromText('POLYGON ((40 170, 90 30, 180 100, 40 170))') AS a,
             ST_GeomFromText('POLYGON ((110 180, 20 60, 130 90, 110 180))') AS b) As t;

 overlaps | crosses | intersects | b_contains_a | dim_a | dim_b | dim_int
----------+---------+------------+--------------+-------+-------+-----------
 t        | f       | t          | f            |     2 |     2 |       2

另请参见

ST_ContainsST_CrossesST_DimensionST_Intersects