Browse Source

v.surf.idw: added missing power parameter from develbranch

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@59107 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 years ago
parent
commit
849a1e0e51
2 changed files with 26 additions and 5 deletions
  1. 16 4
      vector/v.surf.idw/main.c
  2. 10 1
      vector/v.surf.idw/v.surf.idw.html

+ 16 - 4
vector/v.surf.idw/main.c

@@ -62,9 +62,10 @@ int main(int argc, char *argv[])
     double dist;
     double dist;
     double sum1, sum2, interp_value;
     double sum1, sum2, interp_value;
     int n;
     int n;
+    double p;
     struct
     struct
     {
     {
-	struct Option *input, *npoints, *output, *dfield, *col;
+	struct Option *input, *npoints, *power, *output, *dfield, *col;
     } parm;
     } parm;
     struct
     struct
     {
     {
@@ -110,6 +111,15 @@ int main(int argc, char *argv[])
     parm.npoints->answer = "12";
     parm.npoints->answer = "12";
     parm.npoints->guisection = _("Settings");
     parm.npoints->guisection = _("Settings");
 
 
+    parm.power = G_define_option();
+    parm.power->key = "power";
+    parm.power->type = TYPE_DOUBLE;
+    parm.power->answer = "2.0";
+    parm.power->label = _("Power parameter");
+    parm.power->description = 
+    	_("Greater values assign greater influence to closer points");
+    parm.power->guisection = _("Settings");
+
     flag.noindex = G_define_flag();
     flag.noindex = G_define_flag();
     flag.noindex->key = 'n';
     flag.noindex->key = 'n';
     flag.noindex->label = _("Don't index points by raster cell");
     flag.noindex->label = _("Don't index points by raster cell");
@@ -137,7 +147,9 @@ int main(int argc, char *argv[])
     list =
     list =
 	(struct list_Point *) G_calloc((size_t) search_points,
 	(struct list_Point *) G_calloc((size_t) search_points,
 				       sizeof(struct list_Point));
 				       sizeof(struct list_Point));
-    
+
+    p = atof(parm.power->answer);
+
     /* get the window, dimension arrays */
     /* get the window, dimension arrays */
     G_get_window(&window);
     G_get_window(&window);
 
 
@@ -373,8 +385,8 @@ int main(int argc, char *argv[])
 		sum2 = 0.0;
 		sum2 = 0.0;
 		for (n = 0; n < nsearch; n++) {
 		for (n = 0; n < nsearch; n++) {
 		    if ((dist = list[n].dist)) {
 		    if ((dist = list[n].dist)) {
-			sum1 += list[n].z / dist;
-			sum2 += 1.0 / dist;
+			sum1 += list[n].z / pow(dist, p);
+			sum2 += 1.0 / pow(dist, p);
 		    }
 		    }
 		    else {
 		    else {
 			/* If one site is dead on the centre of the cell, ignore
 			/* If one site is dead on the centre of the cell, ignore

+ 10 - 1
vector/v.surf.idw/v.surf.idw.html

@@ -45,7 +45,16 @@ the mean of all the site values will determine the cell value (unless
 the -n flag is specified, in which case only the <em>count</em> 
 the -n flag is specified, in which case only the <em>count</em> 
 points closest to the centre of the cell will be interpolated).
 points closest to the centre of the cell will be interpolated).
 
 
-<p>By setting <em>npoints=1</em>, the module can be used 
+<p>
+The <em>power</em> parameter defines an exponential distance weight.
+Greater values assign greater influence to values closer to the
+point to be interpolated. The interpolation function peaks sharply over
+the given data points for 0 &lt; <em>p</em> &lt; 1 and more smoothly for
+larger values. The default value for the power parameter is 2.  
+
+
+<p>
+By setting <em>npoints=1</em>, the module can be used 
 to calculate raster Voronoi diagrams (Thiessen polygons).
 to calculate raster Voronoi diagrams (Thiessen polygons).