]> granicus.if.org Git - postgis/commitdiff
Added new variant on existing ST_SetValues where instead of a noset 2D
authorBborie Park <bkpark at ucdavis.edu>
Sat, 8 Sep 2012 01:21:21 +0000 (01:21 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Sat, 8 Sep 2012 01:21:21 +0000 (01:21 +0000)
array of booleans, the parameter nosetvalue can be used instead.

git-svn-id: http://svn.osgeo.org/postgis/trunk@10260 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rt_pg.c
raster/rt_pg/rtpostgis.sql.in.c
raster/test/regress/rt_setvalues_array.sql
raster/test/regress/rt_setvalues_array_expected

index 60ec9870fb7808b4d6c8a0930d3331a21b4d91da..47a055bba551f4ea32267b7725f5a3ee9613a4d6 100644 (file)
@@ -2559,6 +2559,9 @@ Datum RASTER_setPixelValuesArray(PG_FUNCTION_ARGS)
        int hasnodata = FALSE;
        double nodataval = 0;
        bool keepnodata = FALSE;
+       bool hasnosetval = FALSE;
+       bool nosetvalisnull = FALSE;
+       double nosetval = 0;
 
        int rtn = 0;
        double val = 0;
@@ -2827,6 +2830,14 @@ Datum RASTER_setPixelValuesArray(PG_FUNCTION_ARGS)
                pfree(elements);
                pfree(nulls);
        }
+       /* hasnosetvalue and nosetvalue */
+       else if (!PG_ARGISNULL(6) & PG_GETARG_BOOL(6)) {
+               hasnosetval = TRUE;
+               if (PG_ARGISNULL(7))
+                       nosetvalisnull = TRUE;
+               else
+                       nosetval = PG_GETARG_FLOAT8(7);
+       }
 
 #if POSTGIS_DEBUG_LEVEL > 0
        for (i = 0; i < numpixval; i++) {
@@ -2842,8 +2853,8 @@ Datum RASTER_setPixelValuesArray(PG_FUNCTION_ARGS)
 #endif
 
        /* keepnodata flag */
-       if (!PG_ARGISNULL(6))
-               keepnodata = PG_GETARG_BOOL(6);
+       if (!PG_ARGISNULL(8))
+               keepnodata = PG_GETARG_BOOL(8);
 
        /* get band */
        band = rt_raster_get_band(raster, nband - 1);
@@ -2868,6 +2879,15 @@ Datum RASTER_setPixelValuesArray(PG_FUNCTION_ARGS)
                /* noset = true, skip */
                if (pixval[i].noset)
                        continue;
+               /* check against nosetval */
+               else if (hasnosetval) {
+                       /* pixel = NULL AND nosetval = NULL */
+                       if (pixval[i].nodata && nosetvalisnull)
+                               continue;
+                       /* pixel value = nosetval */
+                       else if (!pixval[i].nodata && !nosetvalisnull && FLT_EQ(pixval[i].value, nosetval))
+                               continue;
+               }
 
                /* if pixel is outside bounds, skip */
                if (
index a642365840a3668960c762ee7bfb3d470a2f311e..c66d7a3a5f6d592df93b955aa0586da82905512a 100644 (file)
@@ -2903,17 +2903,41 @@ CREATE OR REPLACE FUNCTION st_setvalue(rast raster, pt geometry, newvalue float8
 -----------------------------------------------------------------------
 -- ST_SetValues (set one or more pixels to a one or more values)
 -----------------------------------------------------------------------
-CREATE OR REPLACE FUNCTION st_setvalues(
+CREATE OR REPLACE FUNCTION _st_setvalues(
        rast raster, nband integer,
        x integer, y integer,
        newvalueset double precision[][],
        noset boolean[][] DEFAULT NULL,
+       hasnosetvalue boolean DEFAULT FALSE,
+       nosetvalue double precision DEFAULT NULL,
        keepnodata boolean DEFAULT FALSE
 )
        RETURNS raster
        AS 'MODULE_PATHNAME', 'RASTER_setPixelValuesArray'
        LANGUAGE 'c' IMMUTABLE;
 
+CREATE OR REPLACE FUNCTION st_setvalues(
+       rast raster, nband integer,
+       x integer, y integer,
+       newvalueset double precision[][],
+       noset boolean[][] DEFAULT NULL,
+       keepnodata boolean DEFAULT FALSE
+)
+       RETURNS raster
+       AS $$ SELECT _st_setvalues($1, $2, $3, $4, $5, $6, FALSE, NULL, $7) $$
+       LANGUAGE 'sql' IMMUTABLE;
+
+CREATE OR REPLACE FUNCTION st_setvalues(
+       rast raster, nband integer,
+       x integer, y integer,
+       newvalueset double precision[][],
+       nosetvalue double precision,
+       keepnodata boolean DEFAULT FALSE
+)
+       RETURNS raster
+       AS $$ SELECT _st_setvalues($1, $2, $3, $4, $5, NULL, TRUE, $6, $7) $$
+       LANGUAGE 'sql' IMMUTABLE;
+
 -- cannot be STRICT as newvalue can be NULL
 CREATE OR REPLACE FUNCTION st_setvalues(
        rast raster, nband integer,
@@ -2929,7 +2953,7 @@ CREATE OR REPLACE FUNCTION st_setvalues(
                        RAISE EXCEPTION 'Values for width and height must be greater than zero';
                        RETURN NULL;
                END IF;
-               RETURN st_setvalues($1, $2, $3, $4, array_fill($7, ARRAY[$6, $5]::int[]), NULL, $8);
+               RETURN _st_setvalues($1, $2, $3, $4, array_fill($7, ARRAY[$6, $5]::int[]), NULL, FALSE, NULL, $8);
        END;
        $$
        LANGUAGE 'plpgsql' IMMUTABLE;
@@ -2949,7 +2973,7 @@ CREATE OR REPLACE FUNCTION st_setvalues(
                        RAISE EXCEPTION 'Values for width and height must be greater than zero';
                        RETURN NULL;
                END IF;
-               RETURN st_setvalues($1, 1, $2, $3, array_fill($6, ARRAY[$5, $4]::int[]), NULL, $7);
+               RETURN _st_setvalues($1, 1, $2, $3, array_fill($6, ARRAY[$5, $4]::int[]), NULL, FALSE, NULL, $7);
        END;
        $$
        LANGUAGE 'plpgsql' IMMUTABLE;
index f81d1fba31ec4a2b38eb0e92cd4378497b19f934..b96e40d489c713e7083abec96b874a3c7b43e8e3 100644 (file)
@@ -182,6 +182,36 @@ INSERT INTO raster_setvalues_out VALUES (
        FROM raster_setvalues_rast
 ));
 
+INSERT INTO raster_setvalues_out VALUES (
+       31, (
+       SELECT ST_SetValues(
+               rast, 1, 1, 1,
+               ARRAY[-1, 31, -1]::double precision[],
+               -1::double precision
+       )
+       FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+       32, (
+       SELECT ST_SetValues(
+               rast, 1, 1, 1,
+               ARRAY[[-1, 32, -1], [32, -1, 32]]::double precision[],
+               -1::double precision
+       )
+       FROM raster_setvalues_rast
+));
+
+INSERT INTO raster_setvalues_out VALUES (
+       33, (
+       SELECT ST_SetValues(
+               rast, 1, 1, 1,
+               ARRAY[[NULL, 33, NULL], [33, NULL, 33]]::double precision[],
+               NULL::double precision
+       )
+       FROM raster_setvalues_rast
+));
+
 SELECT
        rid,
        (poly).x,
index 51aa70055da07ddd05ae601b2f09e46f6169b2e2..c2952126bda692282bfcc417ae5da46f865aab7e 100644 (file)
 23|5|1|
 23|5|2|
 23|5|3|
+31|1|1|1
+31|1|2|1
+31|1|3|1
+31|2|1|31
+31|2|2|1
+31|2|3|1
+31|3|1|1
+31|3|2|1
+31|3|3|1
+31|4|1|1
+31|4|2|1
+31|4|3|1
+31|5|1|1
+31|5|2|1
+31|5|3|1
+32|1|1|1
+32|1|2|32
+32|1|3|1
+32|2|1|32
+32|2|2|1
+32|2|3|1
+32|3|1|1
+32|3|2|32
+32|3|3|1
+32|4|1|1
+32|4|2|1
+32|4|3|1
+32|5|1|1
+32|5|2|1
+32|5|3|1
+33|1|1|1
+33|1|2|33
+33|1|3|1
+33|2|1|33
+33|2|2|1
+33|2|3|1
+33|3|1|1
+33|3|2|33
+33|3|3|1
+33|4|1|1
+33|4|2|1
+33|4|3|1
+33|5|1|1
+33|5|2|1
+33|5|3|1