返回一個代表一些Geometry對象并集的Geometry對象。
語法
geometry ST_Union(geometry set g1Field);
geometry ST_Union(geometry g1 , geometry g2);
geometry ST_Union(geometry[] g1Array);
geometry ST_Union(geometry set g1Field, float8 gridsize);
geometry ST_Union(geometry set g1Field, cstring options);
geometry ST_Union(geometry set g1Field, float8 gridsize, cstring options);
geometry ST_Union(geometry[] g1Array, float8 gridsize);
geometry ST_Union(geometry[] g1Array, cstring options);
geometry ST_Union(geometry[] g1Array, float8 gridsize, cstring options);
參數
參數名稱 | 描述 |
g1field | Geometry對象在數據集中的字段。 |
g1 | 第一個Geometry對象。 |
g2 | 第二個Geometry對象。 |
g1Array | Geometry對象數組。 |
gridsize | 指定網格大小,使得union時在相同網格內的頂點會直接合并,默認值為-1.0,表示不啟用。 |
options | 如果要開啟并行執行,可通過options指定并行度。 并行度范圍為1~64,格式為JSON字符串,例如 |
描述
輸出類型可以是Multi類型或GeometryCollection類型。該函數有兩種形式:
形式1:輸入參數是兩個Geometry對象。輸出類型可以是Multi類型,非Multi類型或GeometryCollection。如果任意一個輸入對象是NULL,返回值也是NULL。
形式2:是一個聚合功能函數,輸入對象是一個Geometry對象的集合,輸出類型可能是Multi類型或非Multi類型。
ST_Collect和ST_Union經常可以互換使用。ST_Collect一般來說要比ST_Union快很多,因為ST_Collect不會去分解輸入Geometry對象的邊界或者檢查一個MultiPolygon對象是否有重疊部分。
示例
對比ST_Union和ST_Collect:
SELECT ST_Union(g1,g2),ST_Collect(g1,g2) from (select 'POLYGON((0 0,1 0,1 2,0 2,0 0))'::geometry as g1,'POLYGON((1 0,3 0,3 1,1 1,1 0))'::geometry as g2) as t;
指定gridsize和options:
--指定gridsize select st_area(st_union(geom, 0.005)) from tableA; --指定并行度 select st_area(st_union(geom, '{"parallel": 4}'::cstring)) from tableA; --同時指定gridsize和并行度 select st_area(st_union(geom, 0.005, '{"parallel": 4}'::cstring)) from tableA;
文檔內容是否對您有幫助?