瀏覽代碼

Add "weighted" versions of min, max aggregates
(the actual weights are ignored; this just provides the stat_func_w
interface for compatibility)
Change r.resamp.stats to use w_{min,max}.



git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33888 15284696-431f-4ddb-bdfa-cd5b030d7da7

Glynn Clements 16 年之前
父節點
當前提交
490975fa99
共有 5 個文件被更改,包括 52 次插入3 次删除
  1. 2 0
      include/stats.h
  2. 21 0
      lib/stats/c_max.c
  3. 21 0
      lib/stats/c_min.c
  4. 2 2
      raster/r.resamp.stats/main.c
  5. 6 1
      raster/r.resamp.stats/r.resamp.stats.html

+ 2 - 0
include/stats.h

@@ -33,6 +33,8 @@ extern stat_func c_kurt;
 extern stat_func_w w_ave;
 extern stat_func_w w_count;
 extern stat_func_w w_median;
+extern stat_func_w w_min;
+extern stat_func_w w_max;
 extern stat_func_w w_mode;
 extern stat_func_w w_quart1;
 extern stat_func_w w_quart3;

+ 21 - 0
lib/stats/c_max.c

@@ -20,3 +20,24 @@ void c_max(DCELL * result, DCELL * values, int n)
     else
 	*result = max;
 }
+
+void w_max(DCELL * result, DCELL(*values)[2], int n)
+{
+    DCELL max;
+    int i;
+
+    G_set_d_null_value(&max, 1);
+
+    for (i = 0; i < n; i++) {
+	if (G_is_d_null_value(&values[i][0]))
+	    continue;
+
+	if (G_is_d_null_value(&max) || max < values[i][0])
+	    max = values[i][0];
+    }
+
+    if (G_is_d_null_value(&max))
+	G_set_d_null_value(result, 1);
+    else
+	*result = max;
+}

+ 21 - 0
lib/stats/c_min.c

@@ -20,3 +20,24 @@ void c_min(DCELL * result, DCELL * values, int n)
     else
 	*result = min;
 }
+
+void w_min(DCELL * result, DCELL(*values)[2], int n)
+{
+    DCELL min;
+    int i;
+
+    G_set_d_null_value(&min, 1);
+
+    for (i = 0; i < n; i++) {
+	if (G_is_d_null_value(&values[i][0]))
+	    continue;
+
+	if (G_is_d_null_value(&min) || min > values[i][0])
+	    min = values[i][0];
+    }
+
+    if (G_is_d_null_value(&min))
+	G_set_d_null_value(result, 1);
+    else
+	*result = min;
+}

+ 2 - 2
raster/r.resamp.stats/main.c

@@ -30,8 +30,8 @@ static const struct menu
     {c_ave,    w_ave,    "average",  "average (mean) value"},
     {c_median, w_median, "median",   "median value"},
     {c_mode,   w_mode,   "mode",     "most frequently occuring value"},
-    {c_min,    NULL,     "minimum",  "lowest value"},
-    {c_max,    NULL,     "maximum",  "highest value"},
+    {c_min,    w_min,    "minimum",  "lowest value"},
+    {c_max,    w_max,    "maximum",  "highest value"},
     {c_quart1, w_quart1, "quart1",   "first quartile"},
     {c_quart3, w_quart3, "quart3",   "third quartile"},
     {c_perc90, w_perc90, "perc90",   "ninetieth percentile"},

+ 6 - 1
raster/r.resamp.stats/r.resamp.stats.html

@@ -23,7 +23,12 @@ is slower, but produces a more accurate result.
 Resampling modules (<em>r.resample, r.resamp.stats, r.resamp.interp,
 r.resamp.rst</em>) resample the map to match the current region settings.
 </p>
-
+<p>
+The notion of weighting doesn't make any sense for the min and max
+aggregates. However, the <em>-w</em> flag still has significance in
+that, when multiple destination cells overlap a source cell, the
+source cell is included in the calculation of all of the destination
+cells.
 
 <h2>SEE ALSO</h2>