定义
ST_Overlaps 将以两个几何对象作为输入参数,如果两个对象的交集生成的几何对象维度相同但不等于任一源对象,则返回 1(Oracle 和 SQLite)或 t (PostgreSQL)。否则,返回 0(Oracle 和 SQLite)或 f (PostgreSQL)。
语法
Oracle 和 PostgreSQL
sde.st_overlaps (geometry1 sde.st_geometry, geometry2 sde.st_geometry)
SQLite
st_overlaps (geometry1 geometryblob, geometry2 geometryblob)
返回类型
布尔型
示例
县政委员需要一个包含了与危险废弃物场地缓冲半径区域重叠的敏感区域的列表。除用于存储机构 ST_Polygon 几何的形状列外,sensitive_areas 表还包含几个用于描述受威胁机构的列。
hazardous_sites 表在 ID 列中存储场地标识,而各场地的实际地理位置存储在场地点列中。
ST_Overlaps 函数会将 sensitive_areas 和 hazardous_sites 表连接起来,并返回包含与 hazardous_sites 点缓冲半径区域重叠的面的所有 sensitive_areas 行 ID。
Oracle
CREATE TABLE sensitive_areas (
id integer,
shape sde.st_geometry
);
CREATE TABLE hazardous_sites (
id integer,
site sde.st_geometry
);
INSERT INTO sensitive_areas VALUES (
1,
sde.st_geometry ('polygon ((.20 .30, .30 .30, .30 .40, .20 .40, .20 .30))', 4326)
);
INSERT INTO sensitive_areas VALUES (
2,
sde.st_geometry ('polygon ((.30 .30, .30 .50, .50 .50, .50 .30, .30 .30))', 4326)
);
INSERT INTO sensitive_areas VALUES (
3,
sde.st_geometry ('polygon ((.40 .40, .40 .60, .60 .60, .60 .40, .40 .40))', 4326)
);
INSERT INTO hazardous_sites VALUES (
4,
sde.st_geometry ('point (.60 .60)', 4326)
);
INSERT INTO hazardous_sites VALUES (
5,
sde.st_geometry ('point (.30 .30)', 4326)
);
SELECT UNIQUE (hs.id)
FROM HAZARDOUS_SITES hs, SENSITIVE_AREAS sa
WHERE sde.st_overlaps (sde.st_buffer (hs.site, .001), sa.shape) = 1;
ID
4
5
PostgreSQL
CREATE TABLE sensitive_areas (
id serial,
shape sde.st_geometry
);
CREATE TABLE hazardous_sites (
id serial,
site sde.st_geometry
);
INSERT INTO sensitive_areas (shape) VALUES (
sde.st_geometry ('polygon ((.20 .30, .30 .30, .30 .40, .20 .40, .20 .30))', 4326)
);
INSERT INTO sensitive_areas (shape) VALUES (
sde.st_geometry ('polygon ((.30 .30, .30 .50, .50 .50, .50 .30, .30 .30))', 4326)
);
INSERT INTO sensitive_areas (shape) VALUES (
sde.st_geometry ('polygon ((.40 .40, .40 .60, .60 .60, .60 .40, .40 .40))', 4326)
);
INSERT INTO hazardous_sites (site) VALUES (
sde.st_geometry ('point (.60 .60)', 4326)
);
INSERT INTO hazardous_sites (site) VALUES (
sde.st_geometry ('point (.30 .30)', 4326)
);
SELECT DISTINCT (hs.id) AS "Hazardous Site ID"
FROM hazardous_sites hs, sensitive_areas sa
WHERE sde.st_overlaps (sde.st_buffer (hs.site, .001), sa.shape) = 't';
id
1
2
SQLite
CREATE TABLE sensitive_areas (
id integer primary key autoincrement not null
);
SELECT AddGeometryColumn(
NULL,
'sensitive_areas',
'shape',
4326,
'polygon',
'xy',
'null'
);
CREATE TABLE hazardous_sites (
id integer primary key autoincrement not null,
site_name varchar(30)
);
SELECT AddGeometryColumn(
NULL,
'hazardous_sites',
'site',
4326,
'point',
'xy',
'null'
);
INSERT INTO sensitive_areas (shape) VALUES (
st_geometry ('polygon ((.20 .30, .30 .30, .30 .40, .20 .40, .20 .30))', 4326)
);
INSERT INTO sensitive_areas (shape) VALUES (
st_geometry ('polygon ((.30 .30, .30 .50, .50 .50, .50 .30, .30 .30))', 4326)
);
INSERT INTO sensitive_areas (shape) VALUES (
st_geometry ('polygon ((.40 .40, .40 .60, .60 .60, .60 .40, .40 .40))', 4326)
);
INSERT INTO hazardous_sites (site_name, site) VALUES (
'Kemlabs',
st_geometry ('point (.60 .60)', 4326)
);
INSERT INTO hazardous_sites (site_name, site) VALUES (
'Medi-Waste',
st_geometry ('point (.30 .30)', 4326)
);
SELECT DISTINCT (hs.site_name) AS "Hazardous Site"
FROM hazardous_sites hs, sensitive_areas sa
WHERE st_overlaps (st_buffer (hs.site, .001), sa.shape) = 1;
Hazardous Site
Kemlabs
Medi-Waste