]> granicus.if.org Git - postgis/commitdiff
Nodata mode defaults to 'ignore' if it is NULL. Added tests for out of range neighbor...
authorDavid Zwarg <dzwarg@azavea.com>
Fri, 18 Nov 2011 21:28:04 +0000 (21:28 +0000)
committerDavid Zwarg <dzwarg@azavea.com>
Fri, 18 Nov 2011 21:28:04 +0000 (21:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8185 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rt_pg.c
raster/test/regress/rt_mapalgebrafctngb.sql
raster/test/regress/rt_mapalgebrafctngb_expected

index 0e8d07044a7332286f61699a33fcdf00d0f878d1..ffa59ca9cbe9e76b763499f2ea10e73123c570cc 100644 (file)
@@ -9321,27 +9321,12 @@ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS)
 
     /* Get the type of NODATA behavior for the neighborhoods. */
     if (PG_ARGISNULL(6)) {
-        elog(NOTICE, "Neighborhood NODATA behavior is not specified. Returning new "
-            "raster with the original band");
-
-        /* Serialize created raster */
-        pgraster = rt_raster_serialize(newrast);
-        if (NULL == pgraster) {
-            elog(ERROR, "RASTER_mapAlgebraFctNgb: Could not serialize raster. "
-                "Returning NULL");
-
-            PG_RETURN_NULL();
-        }
-
-        SET_VARSIZE(pgraster, pgraster->size);
-
-        rt_raster_destroy(raster);
-        rt_raster_destroy(newrast);
-
-        PG_RETURN_POINTER(pgraster);      
+        elog(NOTICE, "Neighborhood NODATA behavior defaulting to 'ignore'");
+        txtNodataMode = cstring_to_text("ignore");
+    }
+    else {
+        txtNodataMode = PG_GETARG_TEXT_P(6);
     }
-
-    txtNodataMode = PG_GETARG_TEXT_P(6);
 
     txtCallbackParam = (text*)palloc(VARSIZE(txtNodataMode));
     SET_VARSIZE(txtCallbackParam, VARSIZE(txtNodataMode));
index 977c5d4638fb9c940a1ef8bbc1a4f083e3f6de27..9cb0731987a5f3914a560d54d594d324f54654de 100644 (file)
@@ -8,6 +8,32 @@ SELECT ST_IsEmpty(ST_MapAlgebraFctNgb(ST_MakeEmptyRaster(0, 10, 0, 0, 1, 1, 1, 1
 -- Test has no band raster. Should be true
 SELECT ST_HasNoBand(ST_MapAlgebraFctNgb(ST_MakeEmptyRaster(10, 10, 0, 0, 1, 1, 1, 1, -1), 1, NULL, 1, 1, 'ST_Sum(float[][], text, text[])'::regprocedure, 'NULL', NULL));
 
+-- Test huge neighborhood. Original raster returned.
+SELECT
+  ST_Value(rast, 2, 2) = 1,
+  ST_Value(ST_MapAlgebraFctNgb(
+      rast, 1, NULL, 5, 5, 'ST_Sum(float[][], text, text[])'::regprocedure, 'NULL', NULL
+    ), 2, 2) = 1
+ FROM ST_TestRasterNgb(3, 3, 1) AS rast;
+
+-- Test negative width neighborhood. Original raster returned.
+SELECT 
+  ST_Value(rast, 2, 2) = 1,
+  ST_Value(
+    ST_MapAlgebraFctNgb(
+      rast, 1, NULL, -1, 1, 'ST_Sum(float[][], text, text[])'::regprocedure, 'NULL', NULL
+    ), 2, 2) = 1
+ FROM ST_TestRasterNgb(3, 3, 1) AS rast;
+
+-- Test negative height neighborhood. Original raster returned.
+SELECT 
+  ST_Value(rast, 2, 2) = 1,
+  ST_Value(
+    ST_MapAlgebraFctNgb(
+      rast, 1, NULL, 1, -1, 'ST_Sum(float[][], text, text[])'::regprocedure, 'NULL', NULL
+    ), 2, 2) = 1
+ FROM ST_TestRasterNgb(3, 3, 1) AS rast;
+
 -- Test has no nodata value. Should return null and 7.
 SELECT 
   ST_Value(rast, 2, 2) IS NULL, 
@@ -25,6 +51,14 @@ SELECT
   ) IS NULL
  FROM ST_SetValue(ST_TestRasterNgb(3, 3, 1), 2, 2, NULL) AS rast;
 
+---- Test default nodatamode (ignore). Should return null and 8.
+SELECT 
+  ST_Value(rast, 2, 2) IS NULL, 
+  ST_Value(
+    ST_MapAlgebraFctNgb(rast, 1, NULL, 1, 1, 'ST_Sum(float[][], text, text[])'::regprocedure, NULL, NULL), 2, 2
+  ) = 8
+ FROM ST_SetValue(ST_TestRasterNgb(3, 3, 1), 2, 2, NULL) AS rast;
+
 ---- Test ignore nodatamode. Should return null and 8.
 SELECT 
   ST_Value(rast, 2, 2) IS NULL, 
index f5675eca9926edb98bc82ca57ab6ce62a2d973d7..1994669518667e15848233ba25be2e16b5ccfe9b 100644 (file)
@@ -4,8 +4,15 @@ NOTICE:  Raster is empty. Returning an empty raster
 t
 NOTICE:  Raster does not have the required band. Returning a raster without a band
 t
+t|
+NOTICE:  Neighborhood width is NULL or <= 0. Returning new raster with the original band
+t|
+NOTICE:  Neighborhood height is NULL or <= 0. Returning new raster with the original band
+t|
 t|t
 t|t
+NOTICE:  Neighborhood NODATA behavior defaulting to 'ignore'
+t|t
 t|t
 t|t
 t|t