ST_Union — Returns the union of a set of raster tiles into a single raster composed of 1 band. If no band is specified for unioning, band num 1 is assumed. The resulting raster's extent is the extent of the whole set. In the case of intersection, the resulting value is defined by p_expression which is one of the following: LAST - the default when none is specified, MEAN, SUM, FIRST, MAX, MIN.
raster ST_Union(
setof raster rast)
;
raster ST_Union(
raster set rast, integer band_num)
;
raster ST_Union(
raster set rast, text p_expression)
;
raster ST_Union(
raster set rast, integer band_num, text p_expression)
;
Returns the union of a set of raster tiles into a single raster composed of 1 band. If no band is specified for unioning, band num 1 is assumed. The resulting raster's extent is the extent of the whole set. In the case of intersection, the resulting value is defined by p_expression which is one of the following: LAST - the default when none is specified, MEAN, SUM, FIRST, MAX, MIN
There are several other variants of this function not installed by default in PostGIS 2.0.0 -- these can be found in the raster/scripts/plpgsql/st_union.sql file of postgis source code. |
The ST_Union function in 2.0.0 is currently implemented predominantly in plpgsql. Because of the memory copying needed to copy between the C and plpgsql layer, this function is much much slower than it needs to be. Future 2.0 releases will have this function implemented in C, so you should witness significant improvements in speed when that happens. As a general rule of thumb you want to minimize the size of the rasters, that ST_Union works with. One approach is to clip first and then union the clipped versions. Refer to select parcels example in ST_MapAlgebraExpr. That example if unioning is done before clipping takes about 4 times longer. With the higher res imagery the timing the ratio between is even higher. |
Availability: 2.0.0
-- this creates a single band from first band of raster tiles -- that form the original file system tile SELECT filename, ST_Union(rast) 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 SELECT ST_AddBand(NULL,ARRAY[ST_Union(rast,1), ST_Union(rast,2), ST_Union(rast,3) ]) FROM aerials.boston WHERE ST_Intersects(rast, ST_GeomFromText('LINESTRING(230486 887771, 230500 88772)',26986) );