Ver código fonte

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


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

Martin Landa 11 anos atrás
pai
commit
73233db058

+ 8 - 14
vector/v.surf.idw/main.c

@@ -69,7 +69,7 @@ int main(int argc, char *argv[])
     } parm;
     struct
     {
-	struct Flag *noindex, *withz;
+        struct Flag *noindex;
     } flag;
     struct cell_list
     {
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
     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 @@ int main(int argc, char *argv[])
     
     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 @@ int main(int argc, char *argv[])
 				  " 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 @@ int main(int argc, char *argv[])
 
     /* 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"));

+ 1 - 1
vector/v.surf.idw/proto.h

@@ -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 *);

+ 31 - 14
vector/v.surf.idw/read_sites.c

@@ -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 @@ void read_sites(const char *name, const char *field_name, const char *col, int n
     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 @@ void read_sites(const char *name, const char *field_name, const char *col, int n
 
 	    /* 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 @@ void read_sites(const char *name, const char *field_name, const char *col, int n
 	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);
 }

+ 36 - 38
vector/v.surf.idw/v.surf.idw.html

@@ -1,20 +1,18 @@
 <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>This program allows the user to use a GRASS vector point map file,
-rather than a raster map layer, as input.
-
+<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>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>
 
@@ -26,9 +24,9 @@ system.  The time required to execute is related to the
 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 @@ if they fall outside the mask. Vector points outside the current
 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 &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).
-
+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 @@ Research Laboratory
 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>