名称

ST_Touches — 测试两个几何图形是否至少有一个共同点,但它们的内部不相交

大纲

boolean ST_Touches(geometry A, geometry B);

描述

如果 A 和 B 相交,但它们的内部不相交,则返回 TRUE。 等价地,A和B至少有一个公共点,并且公共点至少位于一个边界内。 对于点/点输入,关系始终为 FALSE,因为点没有边界。

在数学术语中:ST_Touches(A, B) ⇔ (Int(A) ⋂ Int(B) = ∅) ∧ (A ⋂ B ≠ ∅)

如果两个几何图形的 DE-9IM 交集矩阵匹配以下之一,则此关系成立:

  • FT*******

  • F**T*****

  • F***T****

[注意]

此功能自动包括利用几何上可用的任何空间索引的边界框比较。 要避免使用索引,请改用 _ST_Touches

增强:3.0.0 启用了对 GEOMETRYCOLLECTION 的支持

此方法实现了 SQL 1.1 的 OGC 简单功能规范。 s2.1.1.2 // s2.1.13.3

该方法实现了SQL/MM规范。 SQL-MM 3: 5.1.28

示例

ST_Touches 谓词在以下示例中返回 TRUE

Two Polygons touching along a boundary segment.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'POLYGON ((10 190,10 70,80 70,80 130,50 160,120 160,120 190,10 190))'::geometry AS a,
  'POLYGON ((80 110,140 140,190 110,180 40,140 10,80 50,80 70,80 110))'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-01

Two Polygons touching at a boundary point.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'POLYGON ((10 190,10 70,80 70,80 130,50 160,120 160,120 190,10 190))'::geometry AS a,
  'POLYGON ((140 140,190 110,180 40,140 10,80 70,140 140))'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-02

A Polygon and a LineString touching at the line endpoint.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'POLYGON ((80 10,50 40,50 90,80 130,140 120,160 70,140 30,80 10))'::geometry AS a,
  'LINESTRING (30 190,180 150,160 70)'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-03

Two LineStrings touching at their endpoints.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'LINESTRING (10 10,60 140,140 190)'::geometry AS a,
  'LINESTRING (140 190,190 10)'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-04

Two LineStrings touching where an endpoint meets the other line.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'LINESTRING (10 10,60 140,140 190)'::geometry AS a,
  'LINESTRING (60 140,190 10)'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-05

A Point touching a Polygon boundary.

Code
SELECT ST_Touches(a, b)
FROM (SELECT
  'POLYGON ((30 30,10 110,40 190,120 170,180 180,170 100,130 10,30 30))'::geometry AS a,
  'POINT (170 100)'::geometry AS b
) AS example;
栅格输出
t
Figure
Geometry figure for visual-st-touches-06
Code
SELECT ST_Touches('LINESTRING(0 0,1 1,0 2)'::geometry, 'POINT(1 1)'::geometry);
栅格输出
f
Figure
Geometry figure for visual-st-touches-07
Code
SELECT ST_Touches('LINESTRING(0 0,1 1,0 2)'::geometry, 'POINT(0 2)'::geometry);
栅格输出
t
Figure
Geometry figure for visual-st-touches-08