[GRASS-SVN] r59193 - grass/trunk/vector/v.surf.idw

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 4 08:48:33 PST 2014


Author: martinl
Date: 2014-03-04 08:48:33 -0800 (Tue, 04 Mar 2014)
New Revision: 59193

Modified:
   grass/trunk/vector/v.surf.idw/main.c
   grass/trunk/vector/v.surf.idw/proto.h
   grass/trunk/vector/v.surf.idw/read_sites.c
   grass/trunk/vector/v.surf.idw/v.surf.idw.html
Log:
v.surf.idw: remove -z flag (sync with v.surf.rst), z-coordinate is used when input is 3D and column not specified
            manual updated


Modified: grass/trunk/vector/v.surf.idw/main.c
===================================================================
--- grass/trunk/vector/v.surf.idw/main.c	2014-03-04 15:23:21 UTC (rev 59192)
+++ grass/trunk/vector/v.surf.idw/main.c	2014-03-04 16:48:33 UTC (rev 59193)
@@ -69,7 +69,7 @@
     } parm;
     struct
     {
-	struct Flag *noindex, *withz;
+        struct Flag *noindex;
     } flag;
     struct cell_list
     {
@@ -88,7 +88,7 @@
     G_add_keyword(_("interpolation"));
     G_add_keyword(_("IDW"));
     module->description =
-	_("Surface interpolation from vector point data by Inverse "
+	_("Provides surface interpolation from vector point data by Inverse "
 	  "Distance Squared Weighting.");
 
     parm.input = G_define_standard_option(G_OPT_V_INPUT);
@@ -97,7 +97,9 @@
     
     parm.col = G_define_standard_option(G_OPT_DB_COLUMN);
     parm.col->required = NO;
-    parm.col->description = _("Name of attribute column with values to interpolate");
+    parm.col->label = _("Name of attribute column with values to interpolate");
+    parm.col->description = _("If not given and input is 2D vector map then category values are used. "
+                               "If input is 3D vector map then z-coordinates are used.");
     parm.col->guisection = _("Values");
 
     parm.output = G_define_standard_option(G_OPT_R_OUTPUT);
@@ -128,22 +130,14 @@
 				  " in the interpolation");
     flag.noindex->guisection = _("Settings");
 
-    flag.withz = G_define_flag();
-    flag.withz->key = 'z';
-    flag.withz->description = _("Use z coordinates for approximation (3D vector maps only)");
-    flag.withz->guisection = _("Values");
-
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     if (sscanf(parm.npoints->answer, "%d", &search_points) != 1 ||
 	search_points < 1)
-	G_fatal_error(_("Illegal number of interpolation points"),
-		      parm.npoints->key, parm.npoints->answer);
+	G_fatal_error(_("Illegal number (%s) of interpolation points"),
+		      parm.npoints->answer);
     
-    if (!flag.withz->answer && !parm.col->answer)
-	G_fatal_error(_("No attribute column specified"));
-
     list =
 	(struct list_Point *) G_calloc((size_t) search_points,
 				       sizeof(struct list_Point));
@@ -175,7 +169,7 @@
 
     /* read the elevation points from the input sites file */
     read_sites(parm.input->answer, parm.dfield->answer,
-	       parm.col->answer, flag.noindex->answer, flag.withz->answer);
+	       parm.col->answer, flag.noindex->answer);
     
     if (npoints == 0)
 	G_fatal_error(_("No points found"));

Modified: grass/trunk/vector/v.surf.idw/proto.h
===================================================================
--- grass/trunk/vector/v.surf.idw/proto.h	2014-03-04 15:23:21 UTC (rev 59192)
+++ grass/trunk/vector/v.surf.idw/proto.h	2014-03-04 16:48:33 UTC (rev 59193)
@@ -1,5 +1,5 @@
 /* read_sites.c */
-void read_sites(const char *, const char *, const char *, int, int);
+void read_sites(const char *, const char *, const char *, int);
 
 void newpoint(double, double, double, int);
 void calculate_distances(int, int, double, double, int *);

Modified: grass/trunk/vector/v.surf.idw/read_sites.c
===================================================================
--- grass/trunk/vector/v.surf.idw/read_sites.c	2014-03-04 15:23:21 UTC (rev 59192)
+++ grass/trunk/vector/v.surf.idw/read_sites.c	2014-03-04 16:48:33 UTC (rev 59193)
@@ -13,10 +13,10 @@
  * mccauley
  */
 
-void read_sites(const char *name, const char *field_name, const char *col, int noindex, int with_z)
+void read_sites(const char *name, const char *field_name, const char *col, int noindex)
 {
     extern long npoints;
-    int nrec, ctype = 0, type, field;
+    int nrec, ctype = 0, type, field, with_z;
     struct Map_info Map;
     struct field_info *Fi;
     dbDriver *Driver;
@@ -27,8 +27,20 @@
     Vect_set_open_level(1);	/* without topology */
     Vect_open_old2(&Map, name, "", field_name);
     field = Vect_get_field_number(&Map, field_name);
-    
-    if (!with_z) {
+    with_z = col == NULL && Vect_is_3d(&Map); /* read z-coordinates
+                                                 only when column is
+                                                 not defined */
+    if (!col) {
+        if (!with_z)
+            G_important_message(_("Input vector map <%s> is 2D - using categories to interpolate"),
+                                Vect_get_full_name(&Map));
+        else
+            G_important_message(_("Input vector map <%s> is 3D - using z-coordinates to interpolate"),
+                                Vect_get_full_name(&Map));
+
+    }
+
+    if (col) {
 	db_CatValArray_init(&cvarr);
 
 	Fi = Vect_get_field(&Map, field);
@@ -73,16 +85,21 @@
 
 	    /* TODO: what to do with multiple cats */
 	    Vect_cat_get(Cats, field, &cat);
-	    if (cat < 0)
+	    if (cat < 0) /* skip features without category */
 		continue;
 
-	    if (ctype == DB_C_TYPE_INT) {
-		ret = db_CatValArray_get_value_int(&cvarr, cat, &ival);
-		dval = ival;
-	    }
-	    else {		/* DB_C_TYPE_DOUBLE */
-		ret = db_CatValArray_get_value_double(&cvarr, cat, &dval);
-	    }
+            if (col) {
+                if (ctype == DB_C_TYPE_INT) {
+                    ret = db_CatValArray_get_value_int(&cvarr, cat, &ival);
+                    dval = ival;
+                }
+                else {		/* DB_C_TYPE_DOUBLE */
+                    ret = db_CatValArray_get_value_double(&cvarr, cat, &dval);
+                }
+            }
+            else {
+                dval = cat;
+            }
 
 	    if (ret != DB_OK) {
 		G_warning(_("No record for point (cat = %d)"), cat);
@@ -95,11 +112,11 @@
 	newpoint(dval, Points->x[0], Points->y[0], noindex);
     }
 
-    if (!with_z)
+    if (col)
 	db_CatValArray_free(&cvarr);
 
     Vect_set_release_support(&Map);
     Vect_close(&Map);
 
-    G_message(_("%d points loaded"), npoints);
+    G_message(_("%ld points loaded"), npoints);
 }

Modified: grass/trunk/vector/v.surf.idw/v.surf.idw.html
===================================================================
--- grass/trunk/vector/v.surf.idw/v.surf.idw.html	2014-03-04 15:23:21 UTC (rev 59192)
+++ grass/trunk/vector/v.surf.idw/v.surf.idw.html	2014-03-04 16:48:33 UTC (rev 59193)
@@ -1,21 +1,19 @@
 <h2>DESCRIPTION</h2>
 
-<p><em>v.surf.idw</em> fills a raster matrix with interpolated
-values generated from a set of irregularly spaced data
-points using numerical approximation (weighted averaging)
-techniques. The interpolated value of a cell is determined
-by values of nearby data points and the distance of the
-cell from those input points.  In comparison with other
-methods, numerical approximation allows representation of
-more complex surfaces (particularly those with anomalous
-features), restricts the spatial influence of any errors,
-and generates the interpolated surface from the data
-points.
+<p><em>v.surf.idw</em> fills a raster matrix with interpolated values
+generated from a set of irregularly spaced vector data points using
+numerical approximation (weighted averaging) techniques. The
+interpolated value of a cell is determined by values of nearby data
+points and the distance of the cell from those input points.  In
+comparison with other methods, numerical approximation allows
+representation of more complex surfaces (particularly those with
+anomalous features), restricts the spatial influence of any errors,
+and generates the interpolated surface from the data points.
 
-<p>This program allows the user to use a GRASS vector point map file,
-rather than a raster map layer, as input.
+<p>Values to interpolate are read from <b>column</b> option. If this
+option is not given than the program uses <i>categories</i> as values
+to interpolate or <i>z-coordinates</i> if the input vector map is 3D.
 
-
 <h2>NOTES</h2>
 
 <p>The amount of memory used by this program is related to the number
@@ -26,9 +24,9 @@
 resolution of the current region, after an initial delay 
 determined by the time taken to read the input vector points map.
 
-<p>To read and interpolate from the elevation co-ordinates as 3rd dimension
-of the vector geometry, use the <em>-z</em> flag. In this case no <em>column</em>
-parameter has to be specified.
+<p>
+Note that vector features without category in given <b>layer</b> are
+<i>skipped</i>.
 
 <p>If the user has a mask set, then interpolation is only done
 for those cells that fall within the mask. However, all
@@ -37,40 +35,39 @@
 region are not used in the interpolation. A larger region may
 be set and a mask used to limit interpolation to a smaller area
 if it is desired to use vector points from outside the region in the
-interpolation. The <em>-n</em> flag may also be used to
+interpolation. The <b>-n</b> flag may also be used to
 achieve a similar result.
 
-<p>If more than <em>count</em> points fall into one target raster cell, 
+<p>If more than <b>npoints</b> fall into one target raster cell, 
 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> 
-points closest to the centre of the cell will be interpolated).
+the <b>-n</b> flag is specified, in which case only the <b>npoints</b> 
+closest to the centre of the cell will be interpolated).
 
 <p>
-The <em>power</em> parameter defines an exponential distance weight.
+The <b>power</b> 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 < <em>p</em> < 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).
+By setting <b>npoints</b>=1, the module can be used to calculate
+raster Voronoi diagrams (Thiessen polygons).
 
-
 <h2>SEE ALSO</h2>
 
-<em><a href="d.vect.html">d.vect</a></em><br>
-<em><a href="g.region.html">g.region</a></em><br>
-<em><a href="r.surf.contour.html">r.surf.contour</a></em><br>
-<em><a href="r.surf.idw.html">r.surf.idw</a></em><br>
-<em><a href="r.surf.idw2.html">r.surf.idw2</a></em><br>
-<em><a href="r.surf.gauss.html">r.surf.gauss</a></em><br>
-<em><a href="r.surf.fractal.html">r.surf.fractal</a></em><br>
-<em><a href="r.surf.random.html">r.surf.random</a></em><br>
-<em><a href="v.surf.rst.html">v.surf.rst</a></em>
+<em>
+<a href="g.region.html">g.region</a>,
+<a href="r.surf.contour.html">r.surf.contour</a>,
+<a href="r.surf.idw.html">r.surf.idw</a>,
+<a href="r.surf.idw2.html">r.surf.idw2</a>,
+<a href="r.surf.gauss.html">r.surf.gauss</a>,
+<a href="r.surf.fractal.html">r.surf.fractal</a>,
+<a href="r.surf.random.html">r.surf.random</a>,
+<a href="v.surf.rst.html">v.surf.rst</a>
+</em>
 
-<h2>AUTHOR</h2>
+<h2>AUTHORS</h2>
 
 Michael Shapiro,  
 U.S. Army Construction Engineering 
@@ -79,4 +76,5 @@
 Improved algorithm (indexes points according to cell and ignores
 points outside current region) by Paul Kelly
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>



More information about the grass-commit mailing list