]> granicus.if.org Git - postgis/commitdiff
Keep initial value when an expression eveluates to null (#1523)
authorSandro Santilli <strk@keybit.net>
Wed, 1 Feb 2012 11:39:36 +0000 (11:39 +0000)
committerSandro Santilli <strk@keybit.net>
Wed, 1 Feb 2012 11:39:36 +0000 (11:39 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8995 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_pg/rt_pg.c
raster/test/regress/rt_mapalgebraexpr.sql
raster/test/regress/rt_mapalgebraexpr_expected

index 7561d2b4fa2de7c536ab2f0370d3190a75949454..45a0852a1152d47452a7046b26a3160c8d44d84c 100644 (file)
@@ -2847,7 +2847,13 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
         tuptable = SPI_tuptable;
 
         tuple = tuptable->vals[0];
-        newval = atof(SPI_getvalue(tuple, tupdesc, 1));
+        newexpr = SPI_getvalue(tuple, tupdesc, 1);
+        if ( ! newexpr ) {
+            POSTGIS_RT_DEBUG(3, "Constant expression evaluated to NULL, keeping initvalue");
+            newval = newinitialvalue;
+        } else {
+            newval = atof(newexpr);
+        }
 
         SPI_freetuptable(tuptable);
 
@@ -2985,7 +2991,13 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS)
                         tuptable = SPI_tuptable;
 
                         tuple = tuptable->vals[0];
-                        newval = atof(SPI_getvalue(tuple, tupdesc, 1));
+                        tmp = SPI_getvalue(tuple, tupdesc, 1);
+                        if ( tmp ) {
+                            newval = atof(tmp);
+                        } else {
+                            POSTGIS_RT_DEBUGF(3, "Expression for pixel %d,%d (value %g) evaluated to NULL, skip setting", x+1,y+1,r);
+                            newval = newinitialvalue;
+                        }
 
                         SPI_freetuptable(tuptable);
 
index 78a87e9451c65bbbe6c658df511b0321565c978b..be0dc1a0562423377c8cc7c4b09f616a516112d3 100644 (file)
@@ -29,3 +29,7 @@ FROM ST_TestRaster(0, 0, 10) rast,
      generate_series(6, 8) as x,
      generate_series(2, 4) as y
 ORDER BY x, y;
+
+-- Test evaluations to null (see #1523)
+SELECT 'T11.1', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'g from (select NULL as g) as foo', 2), 1, 1) FROM ST_TestRaster(0, 0, 10) rast;
+SELECT 'T11.2', ST_Value(rast, 1, 1), ST_Value(ST_MapAlgebraExpr(rast, 1, NULL, 'g from (select RAST,NULL as g) as foo', 2), 1, 1) FROM ST_TestRaster(0, 0, 10) rast;
index 3aa67d4a7ae3cf4074e5f097e9e086e94e52643a..d89238726b9ddb8f6cc32c50bbcc9d541d224a56 100644 (file)
@@ -22,3 +22,5 @@ T10.7.4|10|28
 T10.8.2|10|50
 T10.8.3|10|37
 T10.8.4|10|30
+T11.1|10|2
+T11.2|10|2