/* Replace the NODATA value with the currently processing pixel. */
neighborData[nIndex] = Float8GetDatum((double)rpix);
neighborNulls[nIndex] = false;
- /* do not increment nNullItems */
+ /* do not increment nNullItems, since the user requested that the */
+ /* neighborhood replace NODATA values with the central pixel value */
}
else {
neighborData[nIndex] = PointerGetDatum(NULL);
* We compute a value only for the withdata value neighborhood since the
* nodata value has already been set by the first optimization
**/
- if (!nNodataOnly && !(nNullSkip && nNullItems > 0) && !(valuereplace && nNullItems > 0)) {
+ if (!(nNodataOnly || /* neighborhood only contains NODATA -- OR -- */
+ (nNullSkip && nNullItems > 0) || /* neighborhood should skip any NODATA cells, and a NODATA cell was detected -- OR -- */
+ (valuereplace && nNullItems > 0))) { /* neighborhood should replace NODATA cells with the central pixel value, and a NODATA cell was detected */
POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraFctNgb: (%dx%d), %dx%d neighborhood",
x, y, winwidth, winheight);
ST_MapAlgebraFctNgb(rast, 1, NULL, 1, 1, 'ST_Nullage(float[][], text, text[])'::regprocedure, 'NULL', NULL), 2, 2
) IS NULL
FROM ST_TestRasterNgb(3, 3, 2) AS rast;
+
+-- 'dog ate my homework' test
+-- raster initialized to one NODATA value, then a literal value passed in as the 'nodatamode' parameter.
+-- expect that the cells processed by the neighborhoods would be replaced by the 'nodatamode' parameter value, and not NODATA.
+SELECT
+ ST_Value(
+ ST_MapAlgebraFctNgb(rast, 1, '8BUI', 1, 1, 'ST_Sum(float[][], text, text[])'::regprocedure, '120', NULL), 2, 2
+ ) = 200
+FROM ST_SetValue(ST_SetBandNoDataValue(ST_TestRasterNgb(3, 3, 10), 0), 2, 2, 0) AS rast;