From ba24e9ce08e4c0e158d19aa72cf2aa3f7be1bc3a Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Mon, 21 Nov 2011 20:09:10 +0000 Subject: [PATCH] Fixed expression parsing in RASTER_mapAlgebra2. Evidently, the count parameter of replace() is an input/output parameter. Associated ticket is #1317. git-svn-id: http://svn.osgeo.org/postgis/trunk@8217 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_pg/rt_pg.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index 9263718e2..9bf796518 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -249,7 +249,7 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS); /* one-raster neighborhood MapAlgebra */ Datum RASTER_mapAlgebraFctNgb(PG_FUNCTION_ARGS); -/* Replace function taken from +/* string replacement function taken from * http://ubuntuforums.org/showthread.php?s=aa6f015109fd7e4c7e30d2fd8b717497&t=141670&page=3 */ /* --------------------------------------------------------------------------- @@ -2860,6 +2860,7 @@ Datum RASTER_mapAlgebraExpr(PG_FUNCTION_ARGS) sprintf(strnewval, "%f", r); if (initexpr != NULL) { + count = 0; newexpr = replace(initexpr, "RAST", strnewval, &count); POSTGIS_RT_DEBUGF(3, "RASTER_mapAlgebraExpr: (%dx%d), " @@ -8468,11 +8469,13 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) if (!PG_ARGISNULL(exprpos[i])) { expr = strtoupper(text_to_cstring(PG_GETARG_TEXT_P(exprpos[i]))); POSTGIS_RT_DEBUGF(3, "raw expr #%d: %s", i, expr); + len = 0; expr = replace(expr, "RAST1", "$1", &len); if (len) { argcount[i]++; argexists[i][0] = 1; } + len = 0; expr = replace(expr, "RAST2", (argexists[i][0] ? "$2" : "$1"), &len); if (len) { argcount[i]++; @@ -8592,7 +8595,8 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) } else hasnodatanodataval = 0; - } break; + break; + } case REGPROCEDUREOID: { POSTGIS_RT_DEBUG(3, "arg 4 is \"userfunction\"!"); if (!PG_ARGISNULL(4)) { @@ -8642,7 +8646,8 @@ Datum RASTER_mapAlgebra2(PG_FUNCTION_ARGS) ufcnullcount++; } } - } break; + break; + } default: elog(ERROR, "RASTER_mapAlgebra2: Invalid data type for expression or userfunction"); for (k = 0; k < set_count; k++) rt_raster_destroy(_rast[k]); -- 2.40.0