From 493f61176d2c5f486ed7ed9db4cd3c6da44a9b0a Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Fri, 27 Jul 2012 19:45:53 +0000 Subject: [PATCH] New and refactored variants of ST_AddBand(). Purely superficial as none of the underlying code has been rewritten for the changes... git-svn-id: http://svn.osgeo.org/postgis/trunk@10129 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_pg/rtpostgis.sql.in.c | 62 +++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 15 deletions(-) diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index cc5758855..883ced8c4 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -187,7 +187,7 @@ CREATE OR REPLACE FUNCTION st_metadata( LANGUAGE 'c' IMMUTABLE STRICT; ----------------------------------------------------------------------- --- Constructors ST_MakeEmptyRaster and ST_AddBand +-- Constructor ST_MakeEmptyRaster ----------------------------------------------------------------------- CREATE OR REPLACE FUNCTION st_makeemptyraster(width int, height int, upperleftx float8, upperlefty float8, scalex float8, scaley float8, skewx float8, skewy float8, srid int4 DEFAULT 0) RETURNS RASTER @@ -218,27 +218,59 @@ CREATE OR REPLACE FUNCTION st_makeemptyraster(rast raster) END; $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; +----------------------------------------------------------------------- +-- Constructor ST_AddBand +----------------------------------------------------------------------- + +CREATE TYPE addbandarg AS ( + index int, + pixeltype text, + initialvalue float8, + nodataval float8 +); + +CREATE OR REPLACE FUNCTION st_addband(rast raster, addbandargset addbandarg[]) + RETURNS RASTER + AS 'MODULE_PATHNAME', 'RASTER_addBand' + LANGUAGE 'c' IMMUTABLE STRICT; + -- This function can not be STRICT, because nodataval can be NULL indicating that no nodata value should be set -CREATE OR REPLACE FUNCTION st_addband(rast raster, index int, pixeltype text, initialvalue float8 DEFAULT 0., nodataval float8 DEFAULT NULL) - RETURNS RASTER - AS 'MODULE_PATHNAME', 'RASTER_addband' - LANGUAGE 'c' IMMUTABLE; +CREATE OR REPLACE FUNCTION st_addband( + rast raster, + index int, + pixeltype text, + initialvalue float8 DEFAULT 0., + nodataval float8 DEFAULT NULL +) + RETURNS raster + AS $$ SELECT st_addband($1, ARRAY[ROW($2, $3, $4, $5)]::addbandarg[]) $$ + LANGUAGE 'sql' IMMUTABLE; -- This function can not be STRICT, because nodataval can be NULL indicating that no nodata value should be set -CREATE OR REPLACE FUNCTION st_addband(rast raster, pixeltype text, initialvalue float8 DEFAULT 0., nodataval float8 DEFAULT NULL) - RETURNS raster - AS 'select st_addband($1, NULL, $2, $3, $4)' - LANGUAGE 'sql' IMMUTABLE; +CREATE OR REPLACE FUNCTION st_addband( + rast raster, + pixeltype text, + initialvalue float8 DEFAULT 0., + nodataval float8 DEFAULT NULL +) + RETURNS raster + AS $$ SELECT st_addband($1, ARRAY[ROW(NULL, $2, $3, $4)]::addbandarg[]) $$ + LANGUAGE 'sql' IMMUTABLE; -- This function can not be STRICT, because torastindex can not be determined (could be st_numbands(raster) though) -CREATE OR REPLACE FUNCTION st_addband(torast raster, fromrast raster, fromband int DEFAULT 1, torastindex int DEFAULT NULL) - RETURNS RASTER - AS 'MODULE_PATHNAME', 'RASTER_copyband' - LANGUAGE 'c' IMMUTABLE; - +CREATE OR REPLACE FUNCTION st_addband( + torast raster, + fromrast raster, + fromband int DEFAULT 1, + torastindex int DEFAULT NULL +) + RETURNS raster + AS 'MODULE_PATHNAME', 'RASTER_copyband' + LANGUAGE 'c' IMMUTABLE; + -- Variant that adds multiple raster bands in one array call -- -- If null is passed in for the torast, then array of rasts is accumulated. -CREATE OR REPLACE FUNCTION ST_AddBand(torast raster, fromrasts raster[], fromband integer DEFAULT 1) +CREATE OR REPLACE FUNCTION st_addband(torast raster, fromrasts raster[], fromband integer DEFAULT 1) RETURNS raster AS $$ DECLARE var_result raster := torast; -- 2.40.0