# ST_Union

## 定义

ST_Union 返回两个源对象组合而成的 ST_Geometry 对象。

## 语法

`sde.st_union (g1 sde.st_geometry, g2 sde.st_geometry)`

ST_Geometry

## 示例

hazardous_sites 表在 ID 列中存储场地标识，而各场地的实际地理位置存储在场地点列中。

``````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))', 0)
);

INSERT INTO SENSITIVE_AREAS VALUES (
2,
sde.st_geometry ('polygon ((30 30, 30 50, 50 50, 50 30, 30 30))', 0)
);

INSERT INTO SENSITIVE_AREAS VALUES (
3,
sde.st_geometry ('polygon ((40 40, 40 60, 60 60, 60 40, 40 40))', 0)
);

INSERT INTO HAZARDOUS_SITES VALUES (
4,
sde.st_geometry ('point (60 60)', 0)
);

INSERT INTO HAZARDOUS_SITES VALUES (
5,
sde.st_geometry ('point (30 30)', 0)
);
``````

ST_Buffer 函数生成一个环绕危险废弃物场地的缓冲区域。ST_Union 函数从缓冲危险废弃场地和敏感区域面的并集生成面。ST_Area 函数返回这些面的面积。

Oracle

``````SELECT sa.id SA_ID, hs.id HS_ID,
sde.st_area (sde.st_union (sde.st_buffer (hs.site, .01), sa.shape)) UNION_AREA
FROM HAZARDOUS_SITES hs, SENSITIVE_AREAS sa;

SA_ID  HS_ID     UNION_AREA

1    4       100.000313935011
2    4       400.000313935011
3    4       400.000235451258
1    5       100.000235451258
2    5       400.000235451258
3    5       400.000313935011
``````

PostgreSQL

``````SELECT sa.id AS SA_ID, hs.id AS HS_ID,
sde.st_area (sde.st_union (sde.st_buffer (hs.site, .01), sa.shape)) AS UNION_AREA
FROM hazardous_sites hs, sensitive_areas sa;

sa_id  hs_id   union_area

1    4       100.000313935011
2    4       400.000313935011
3    4       400.000235451258
1    5       100.000235451258
2    5       400.000235451258
3    5       400.000313935011
``````
9/15/2013