定义
ST_Equals 比较两个几何,如果这两个几何完全相同,则返回 1(Oracle 和 SQLite)或 t (PostgreSQL);否则返回 0(Oracle 和 SQLite)或 f (PostgreSQL)。
语法
Oracle 和 PostgreSQL
sde.st_equals (geometry1 sde.st_geometry, geometry2 sde.st_geometry)
SQLite
st_equals (geometry1 geometryblob, geometry2 geometryblob)
返回类型
布尔型
示例
城市 GIS 技术人员怀疑 studies 表中的某些数据存在重复。为减轻顾虑,他查询该表,以确定是否存在相等的形状多面。
通过以下语句创建并填充 studies 表。id 列唯一标识研究区域,而形状字段存储区域的几何。
接下来,通过 equal 谓词将 studies 表与其本身进行空间连接,只要发现两个多面相等,就会返回 1(Oracle 和 SQLite)或 t (PostgreSQL)。s1.id<>s2.id 条件不用将几何与其本身进行比较。
Oracle
CREATE TABLE studies (
id integer unique,
shape sde.st_geometry
);
INSERT INTO studies (id, shape) VALUES (
1,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
INSERT INTO studies (id, shape) VALUES (
2,
sde.st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 4326)
);
INSERT INTO studies (id, shape) VALUES (
3,
sde.st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 4326)
);
INSERT INTO studies (id, shape) VALUES (
4,
sde.st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
SELECT UNIQUE (s1.id), s2.id
FROM STUDIES s1, STUDIES s2
WHERE sde.st_equals (s1.shape, s2.shape) = 1
AND s1.id <> s2.id;
ID ID
4 1
1 4
PostgreSQL
CREATE TABLE studies (
id serial,
shape st_geometry
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
SELECT DISTINCT (s1.id), s2.id
FROM studies s1, studies s2
WHERE st_equals (s1.shape, s2.shape) = 't'
AND s1.id <> s2.id;
id id
1 4
4 1
SQLite
CREATE TABLE studies (
id integer primary key autoincrement not null
);
SELECT AddGeometryColumn (
NULL,
'studies',
'shape',
4326,
'polygon',
'xy',
'null'
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((20 0, 20 10, 30 10, 30 0, 20 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((40 0, 40 10, 50 10, 50 0, 40 0))', 4326)
);
INSERT INTO studies (shape) VALUES (
st_polygon ('polygon ((0 0, 0 10, 10 10, 10 0, 0 0))', 4326)
);
SELECT DISTINCT (s1.id), s2.id
FROM studies s1, studies s2
WHERE st_equals (s1.shape, s2.shape) = 1
AND s1.id <> s2.id;
id id
1 4
4 1