定义
ST_Relate 比较两个几何,如果几何满足 DE-9IM 模式矩阵字符串指定的条件,则返回 1(Oracle 和 SQLite)或 t (PostgreSQL)。否则,返回 0(Oracle 和 SQLite)或 f (PostgreSQL)。
语法
Oracle 和 PostgreSQL
sde.st_relate (geometry1 sde.st_geometry, geometry2 sde.st_geometry, patternMatrix string)
SQLite
st_relate (geometry1 geometryblob, geometry2 geometryblob, patternMatrix string)
返回类型
布尔型
示例
DE-9IM 模式矩阵是一种用于比较几何的设备。此矩阵分为多种类型。例如,相等模式矩阵 (T*F**FFF*) 将告知您任意两几何是否相等。
本示例中,将创建包含三个空间列的表 relate_test,每个空间列中均插入了点要素。ST_Relate 函数用于在 SELECT 语句中测试各点是否相同。请注意,如果想要确定几何是否相等,则建议使用 ST_Equals 函数。
Oracle
CREATE TABLE relate_test (
g1 sde.st_geometry,
g2 sde.st_geometry,
g3 sde.st_geometry
);
INSERT INTO relate_test (g1, g2, g3) VALUES (
sde.st_geometry ('point (10.02 20.01)', 4326),
sde.st_geometry ('point (10.02 20.01)', 4326),
sde.st_geometry ('point (30.01 20.01)', 4326)
);
SELECT sde.st_relate (g1, g2, 'T*F**FFF*') g1_equals_g2,
sde.st_relate (g1, g3, 'T*F**FFF*') g1_equals_g3,
sde.st_relate (g2, g3, 'T*F**FFF*') g2_equals_g3
FROM RELATE_TEST;
g1_equals_g2 g1_equals_g3 g2_equals_g3
1 0 0
PostgreSQL
CREATE TABLE relate_test (
g1 sde.st_geometry,
g2 sde.st_geometry,
g3 sde.st_geometry
);
INSERT INTO relate_test (g1, g2, g3) VALUES (
sde.st_geometry ('point (10.02 20.01)', 4326),
sde.st_geometry ('point (10.02 20.01)', 4326),
sde.st_geometry ('point (30.01 20.01)', 4326)
);
SELECT st_relate (g1, g2, 'T*F**FFF*') AS "g1=g2",
st_relate (g1, g3, 'T*F**FFF*') AS "g1=g3",
st_relate (g2, g3, 'T*F**FFF*') AS "g2=g3"
FROM relate_test;
g1=g2 g1=g3 g2=g3
t f f
SQLite
CREATE TABLE relate_test (id integer primary key autoincrement not null);
SELECT AddGeometryColumn(
NULL,
'relate_test',
'g1',
4326,
'point',
'xy',
'null'
);
CREATE TABLE relate_test2 (id integer primary key autoincrement not null);
SELECT AddGeometryColumn(
NULL,
'relate_test2',
'g2',
4326,
'point',
'xy',
'null'
);
CREATE TABLE relate_test3 (id integer primary key autoincrement not null);
SELECT AddGeometryColumn(
NULL,
'relate_test3',
'g3',
4326,
'point',
'xy',
'null'
);
INSERT INTO relate_test (g1) VALUES (
st_geometry ('point (10.02 20.01)', 4326)
);
INSERT INTO relate_test2 (g2) VALUES (
st_geometry ('point (10.02 20.01)', 4326)
);
INSERT INTO relate_test3 (g3) VALUES (
st_geometry ('point (30.01 20.01)', 4326)
);
SELECT st_relate (relate_test.g1, relate_test2.g2, 'T*F**FFF*') AS "g1=g2",
st_relate (relate_test.g1, relate_test3.g3, 'T*F**FFF*') AS "g1=g3",
st_relate (relate_test2.g2, relate_test3.g3, 'T*F**FFF*') AS "g2=g3"
FROM relate_test, relate_test2, relate_test3;
g1=g2 g1=g3 g2=g3
1 0 0