ST_Union — 将一组栅格切片的并集返回为由 1 个或多个波段组成的单个栅格。
raster ST_Union(setof raster  rast);
raster ST_Union(setof raster  rast, unionarg[]  unionargset);
raster ST_Union(setof raster rast, integer nband);
raster ST_Union(setof raster rast, text uniontype);
raster ST_Union(setof raster rast, integer nband, text uniontype);
将一组栅格切片的并集返回为由至少一个波段组成的单个栅格。 生成的栅格范围是整个栅格集的范围。 在交集的情况下,结果值由 uniontype 定义,它是以下之一:LAST(默认)、FIRST、MIN、MAX、COUNT、SUM、MEAN、RANGE。
| ![[Note]](../images/note.png)  | |
| 为了合并栅格,它们必须具有相同的对齐方式。 使用 ST_SameAlignment和 ST_NotSameAlignmentReason 获取更多详细信息和帮助。 解决对齐问题的一种方法是使用 ST_Resample并使用相同的参考栅格进行对齐。 | 
可用性: 2.0.0
增强:2.1.0 提高速度(完全基于 C)。
可用性:2.1.0 引入了 ST_Union(rast, unionarg) 变体。
增强:2.1.0 ST_Union(rast)(变体 1)合并所有输入栅格的所有波段。 PostGIS 的早期版本采用第一个波段。
增强:2.1.0 ST_Union(rast, uniontype)(变体 4)合并所有输入栅格的所有波段。
-- this creates a single band from first band of raster tiles
-- that form the original file system tile
SELECT filename, ST_Union(rast,1) As file_rast
FROM sometable WHERE filename IN('dem01', 'dem02') GROUP BY filename;
                    
      -- this creates a multi band raster collecting all the tiles that intersect a line
-- Note: In 2.0, this would have just returned a single band raster
-- , new union works on all bands by default
-- this is equivalent to unionarg: ARRAY[ROW(1, 'LAST'), ROW(2, 'LAST'), ROW(3, 'LAST')]::unionarg[]
SELECT ST_Union(rast)
FROM aerials.boston
WHERE ST_Intersects(rast,  ST_GeomFromText('LINESTRING(230486 887771, 230500 88772)',26986) );
                    
      如果我们只想要波段的子集或者想要更改波段的顺序,则这里我们使用更长的语法
-- this creates a multi band raster collecting all the tiles that intersect a line
SELECT ST_Union(rast,ARRAY[ROW(2, 'LAST'), ROW(1, 'LAST'), ROW(3, 'LAST')]::unionarg[])
FROM aerials.boston
WHERE ST_Intersects(rast,  ST_GeomFromText('LINESTRING(230486 887771, 230500 88772)',26986) );