]> granicus.if.org Git - postgis/commitdiff
Fixed expression parsing in RASTER_mapAlgebra2. Evidently, the count parameter of...
authorBborie Park <bkpark at ucdavis.edu>
Mon, 21 Nov 2011 20:09:10 +0000 (20:09 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Mon, 21 Nov 2011 20:09:10 +0000 (20:09 +0000)
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

index 9263718e287afb218edc05504fa98b8b0a130c90..9bf7965189dba3e9b00d9ebda0c291a0a2511052 100644 (file)
@@ -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]);