定义
ST_SymmetricDiff 以两个几何对象作为输入参数,并返回由源对象的非公共部分组成的几何对象。
语法
Oracle 和 PostgreSQL
sde.st_symmetricdiff (geometry1 sde.st_geometry, geometry2 sde.st_geometry)
SQLite
st_symmetricdiff (geometry1 geometryblob, geometry2 geometryblob)
返回类型
Oracle 和 PostgreSQL
ST_Geometry
SQLite
Geometryblob
示例
对于特定报表,县政委员必须确定不相交流域和危险污染源半径区域。
流域表包含 id 列以存储流域名称 (wname),以及形状列以存储流域区域几何。
污染源表在 id 列中存储场地标识,而各场地的实际地理位置存储在场地点列中。
ST_Buffer 函数生成一个环绕危险废弃物场地点的缓冲区域。ST_SymmetricDiff 函数将返回不相交的缓冲危险废弃物场地和流域的面。
对危险废弃物场地与流域的交集取反可生成相交区域的差集。
Oracle
CREATE TABLE watershed (
id integer,
wname varchar(40),
shape sde.st_geometry
);
CREATE TABLE plumes (
id integer,
site sde.st_geometry
);
INSERT INTO WATERSHED (ID, WNAME, SHAPE) VALUES (
1,
'Big River',
sde.st_geometry ('polygon ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO WATERSHED (ID, WNAME, SHAPE) VALUES (
2,
'Lost Creek',
sde.st_geometry ('polygon ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO WATERSHED (ID, WNAME, SHAPE) VALUES (
3,
'Szymborska Stream',
sde.st_geometry ('polygon ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO PLUMES (ID, SITE) VALUES (
20,
sde.st_geometry ('point (60 60)', 4326)
);
INSERT INTO PLUMES (ID, SITE) VALUES (
21,
sde.st_geometry ('point (30 30)', 4326)
);
SELECT ws.id WS_ID,
sde.st_area (sde.st_symmetricdiff (sde.st_buffer (p.site, .1), ws.shape)) AREA_NO_INT
FROM PLUMES p, WATERSHED ws
WHERE p.id = 20;
SA_ID AREA_NO_INT
1 100.031393
2 400.031393
3 400.015697
PostgreSQL
CREATE TABLE watershed (
id serial,
wname varchar(40),
shape sde.st_geometry
);
CREATE TABLE plumes (
id serial,
site sde.st_geometry
);
INSERT INTO watershed (wname, shape) VALUES (
'Big River',
sde.st_geometry ('polygon ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO watershed (wname, shape) VALUES (
'Lost Creek',
sde.st_geometry ('polygon ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO watershed (wname, shape) VALUES (
'Szymborska Stream',
sde.st_geometry ('polygon ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO plumes (site) VALUES (
sde.st_geometry ('point (60 60)', 4326)
);
INSERT INTO plumes (site) VALUES (
sde.st_geometry ('point (30 30)', 4326)
);
SELECT ws.id AS WS_ID,
sde.st_area (sde.st_symmetricdiff (sde.st_buffer (p.site, .1), ws.shape)) AS "no intersection"
FROM plumes p, watershed ws
WHERE p.id = 1;
ws_id no intersection
1 100.031393502001
2 400.031393502001
3 400.01569751
SQLite
CREATE TABLE watershed (
id integer primary key autoincrement not null,
wname text(40)
);
SELECT AddGeometryColumn(
NULL,
'watershed',
'shape',
4326,
'polygon',
'xy',
'null'
);
CREATE TABLE plumes (
id integer primary key autoincrement not null
);
SELECT AddGeometryColumn(
NULL,
'plumes',
'site',
4326,
'point',
'xy',
'null'
);
INSERT INTO watershed (wname, shape) VALUES (
'Big River',
st_geometry ('polygon ((20 30, 30 30, 30 40, 20 40, 20 30))', 4326)
);
INSERT INTO watershed (wname, shape) VALUES (
'Lost Creek',
st_geometry ('polygon ((30 30, 30 50, 50 50, 50 30, 30 30))', 4326)
);
INSERT INTO watershed (wname, shape) VALUES (
'Szymborska Stream',
st_geometry ('polygon ((40 40, 40 60, 60 60, 60 40, 40 40))', 4326)
);
INSERT INTO plumes (site) VALUES (
st_geometry ('point (60 60)', 4326)
);
INSERT INTO plumes (site) VALUES (
st_geometry ('point (30 30)', 4326)
);
SELECT ws.id AS WS_ID,
st_area (st_symmetricdiff (st_buffer (p.site, .1), ws.shape)) AS "no intersection"
FROM plumes p, watershed ws
WHERE p.id = 1;
WS_ID no intersection
1 400.031393502001
2 100.031393502001
3 400.01569751