定义
如果两个几何的公共点都不与两个几何的内部相交,则 ST_Touches 返回 1(Oracle 和 SQLite)或 t (PostgreSQL);否则,返回 0(Oracle 和 SQLite)或 f (PostgreSQL)。其中至少一个几何必须是 ST_LineString、ST_Polygon、ST_MultiLineString 或 ST_MultiPolygon。
语法
Oracle 和 PostgreSQL
sde.st_touches (geometry1 sde.st_geometry, geometry2 sde.st_geometry)
SQLite
st_touches (geometry1 geometryblob, geometry2 geometryblob)
返回类型
布尔型
示例
公司老板要其 GIS 技术人员提供具有与其他下水道管线相交的端点的所有下水道管线的列表。
创建 sewerlines 表,表中包含三个列。第一列 (sewer_id) 用于唯一标识各下水道管线。整型类列用于标识通常与管线容量有关的下水道管线类型。下水道列用于存储下水道管线的几何。
SELECT 查询使用 ST_Touches 函数返回彼此相接的下水道列表。
Oracle
CREATE TABLE sewerlines (
sewer_id integer,
sewer sde.st_geometry
);
INSERT INTO SEWERLINES VALUES (
1,
sde.st_mlinefromtext ('multilinestring ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO SEWERLINES VALUES (
2,
sde.st_mlinefromtext ('multilinestring ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO SEWERLINES VALUES (
3,
sde.st_mlinefromtext ('multilinestring ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO SEWERLINES VALUES (
4,
sde.st_linestring ('linestring (60 60, 70 70)', 4326)
);
INSERT INTO SEWERLINES VALUES (
5,
sde.st_linestring ('linestring (30 30, 60 60)', 4326)
);
SELECT s1.sewer_id, s2.sewer_id
FROM SEWERLINES s1, SEWERLINES s2
WHERE sde.st_touches (s1.sewer, s2.sewer) = 1;
SEWER_ID SEWER_ID
1 5
3 4
4 3
4 5
5 1
5 3
5 4
PostgreSQL
CREATE TABLE sewerlines (
sewer_id serial,
sewer sde.st_geometry);
INSERT INTO sewerlines (sewer) VALUES (
sde.st_multilinestring ('multilinestring ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
sde.st_multilinestring ('multilinestring ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
sde.st_multilinestring ('multilinestring ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
sde.st_linestring ('linestring (60 60, 70 70)', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
sde.st_linestring ('linestring (30 30, 60 60)', 4326)
);
SELECT s1.sewer_id, s2.sewer_id
FROM sewerlines s1, sewerlines s2
WHERE sde.st_touches (s1.sewer, s2.sewer) = 't';
SEWER_ID SEWER_ID
1 5
3 4
4 3
4 5
5 1
5 3
5 4
SQLite
CREATE TABLE sewerlines (
sewer_id integer primary key autoincrement not null
);
SELECT AddGeometryColumn(
NULL,
'sewerlines',
'sewer',
4326,
'geometry',
'xy',
'null'
);
INSERT INTO sewerlines (sewer) VALUES (
st_multilinestring ('multilinestring ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
st_multilinestring ('multilinestring ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
st_multilinestring ('multilinestring ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
st_linestring ('linestring (60 60, 70 70)', 4326)
);
INSERT INTO sewerlines (sewer) VALUES (
st_linestring ('linestring (30 30, 60 60)', 4326)
);
SELECT s1.sewer_id, s2.sewer_id
FROM SEWERLINES s1, SEWERLINES s2
WHERE st_touches (s1.sewer, s2.sewer) = 1;
sewer_id sewer_id
1 5
3 4
3 5
4 3
4 5
5 1
5 3
5 4