--- /dev/null
+-----------------------------------------------------------------------\r
+-- ST_MultiBandMapAlgebra\r
+-- Return the same map algebra expression to all the band of a raster. \r
+-----------------------------------------------------------------------\r
+CREATE OR REPLACE FUNCTION ST_MultiBandMapAlgebra(rast1 raster, \r
+ rast2 raster, \r
+ expression text, \r
+ extentexpr text) \r
+ RETURNS raster AS \r
+ $$\r
+ DECLARE\r
+ numband int;\r
+ newrast raster;\r
+ pixeltype text;\r
+ nodataval float;\r
+ BEGIN\r
+ numband := ST_NumBands(rast1);\r
+ IF numband != ST_NumBands(rast2) THEN\r
+ RAISE EXCEPTION 'ST_MultiBandMapAlgebra: Rasters do not have the same number of band';\r
+ END IF;\r
+ newrast := ST_MakeEmptyRaster(rast1);\r
+ FOR b IN 1..numband LOOP\r
+ pixeltype := ST_BandPixelType(rast1, b);\r
+ nodataval := ST_BandNodataValue(rast1, b);\r
+ newrast := ST_AddBand(newrast, NULL, ST_MapAlgebraExpr(rast1, b, rast2, b, expression, pixeltype, extentexpr, nodataval), 1);\r
+ END LOOP;\r
+ END;\r
+ $$\r
+ LANGUAGE 'plpgsql';
\ No newline at end of file