瀏覽代碼

v.univar: check if column exists
extend example in the manual
(merge r63889-90 from trunk)


git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@63891 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 10 年之前
父節點
當前提交
ad91f8add6
共有 2 個文件被更改,包括 83 次插入15 次删除
  1. 11 9
      vector/v.univar/main.c
  2. 72 6
      vector/v.univar/v.univar.html

+ 11 - 9
vector/v.univar/main.c

@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
     G_add_keyword(_("attribute table"));
     G_add_keyword(_("attribute table"));
     G_add_keyword(_("geometry"));
     G_add_keyword(_("geometry"));
     module->label =
     module->label =
-	_("Calculates univariate statistics for attribute.");
+	_("Calculates univariate statistics of vector map features.");
     module->description = _("Variance and standard "
     module->description = _("Variance and standard "
 			    "deviation is calculated only for points if specified.");
 			    "deviation is calculated only for points if specified.");
 
 
@@ -347,17 +347,19 @@ void select_from_database(void)
 		      Fi->database, Fi->driver);
 		      Fi->database, Fi->driver);
     db_set_error_handler_driver(Driver);
     db_set_error_handler_driver(Driver);
 
 
+    /* check if column exists */
+    ctype = db_column_Ctype(Driver, Fi->table, col_opt->answer);
+    if (ctype == -1)
+        G_fatal_error(_("Column <%s> not found in table <%s>"),
+                      col_opt->answer, Fi->table);
+    if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
+	G_fatal_error(_("Only numeric column type is supported"));
+    
     /* Note do not check if the column exists in the table because it may be an expression */
     /* Note do not check if the column exists in the table because it may be an expression */
     db_CatValArray_init(&Cvarr);
     db_CatValArray_init(&Cvarr);
-    nrec =
-	db_select_CatValArray(Driver, Fi->table, Fi->key, col_opt->answer,
-			      where_opt->answer, &Cvarr);
+    nrec = db_select_CatValArray(Driver, Fi->table, Fi->key, col_opt->answer,
+                                 where_opt->answer, &Cvarr);
     G_debug(2, "db_select_CatValArray() nrec = %d", nrec);
     G_debug(2, "db_select_CatValArray() nrec = %d", nrec);
-
-    ctype = Cvarr.ctype;
-    if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
-	G_fatal_error(_("Column type not supported"));
-
     if (nrec < 0)
     if (nrec < 0)
 	G_fatal_error(_("Unable to select data from table"));
 	G_fatal_error(_("Unable to select data from table"));
 
 

+ 72 - 6
vector/v.univar/v.univar.html

@@ -1,12 +1,12 @@
 <h2>DESCRIPTION</h2>
 <h2>DESCRIPTION</h2>
 
 
 <em>v.univar</em> calculates univariate statistics of vector map features.
 <em>v.univar</em> calculates univariate statistics of vector map features.
-This includes the number of features counted, minimum and maximum values,
+This includes the number of features counted, minimum, maximum values,
 and range. 
 and range. 
 Variance and standard deviation is calculated only for points if
 Variance and standard deviation is calculated only for points if
 <b>type=point</b> is defined.
 <b>type=point</b> is defined.
 
 
-<p>Extended statistics adds median, 1st and 3rd quartiles, and 90th
+<p>Extended statistics (<b>-e</b>) adds median, 1st and 3rd quartiles, and 90th
 percentile to the output.
 percentile to the output.
 
 
 <h2>NOTES</h2>
 <h2>NOTES</h2>
@@ -31,17 +31,83 @@ v.random output=samples npoints=100
 v.db.addtable map=samples columns="heights double precision"
 v.db.addtable map=samples columns="heights double precision"
 v.what.rast map=samples rast=elevation column=heights
 v.what.rast map=samples rast=elevation column=heights
 v.db.select map=samples
 v.db.select map=samples
+</pre></div>
+
+Calculate height attribute statistics:
 
 
-# calculate height attribute statistics:
+<div class="code"><pre>
 v.univar -e samples column=heights type=point
 v.univar -e samples column=heights type=point
+    
+number of features with non NULL attribute: 100
+number of missing attributes: 0
+number of NULL attributes: 0
+minimum: 57.2799
+maximum: 148.903
+range: 91.6235
+sum: 10825.6
+mean: 108.256
+mean of absolute values: 108.256
+population standard deviation: 20.2572
+population variance: 410.356
+population coefficient of variation: 0.187123
+sample standard deviation: 20.3593
+sample variance: 414.501
+kurtosis: -0.856767
+skewness: 0.162093
+1st quartile: 90.531
+median (even number of cells): 106.518
+3rd quartile: 126.274
+90th percentile: 135.023
+</pre></div>
+
+Compare to statistics of original raster map:
 
 
-# compare to statistics of original raster map:
+<div class="code"><pre>
 r.univar -e elevation
 r.univar -e elevation
 
 
-# calculate distance between sampling points statistics:
-v.univar -d samples column=heights type=point
+total null and non-null cells: 2025000
+total null cells: 0
+
+Of the non-null cells:
+----------------------
+n: 2025000
+minimum: 55.5788
+maximum: 156.33
+range: 100.751
+mean: 110.375
+mean of absolute values: 110.375
+standard deviation: 20.3153
+variance: 412.712
+variation coefficient: 18.4057 %
+sum: 223510266.558102
+1st quartile: 94.79
+median (even number of cells): 108.88
+3rd quartile: 126.792
+90th percentile: 138.66
 </pre></div>
 </pre></div>
 
 
+Calculate distance between sampling points statistics:
+
+<div class="code"><pre>
+v.univar -d samples column=heights type=point
+
+number of primitives: 100
+number of non zero distances: 4851
+number of zero distances: 0
+minimum: 69.9038
+maximum: 18727.7
+range: 18657.8
+sum: 3.51907e+07
+mean: 7254.33
+mean of absolute values: 7254.33
+population standard deviation: 3468.53
+population variance: 1.20307e+07
+population coefficient of variation: 0.478132
+sample standard deviation: 3468.89
+sample variance: 1.20332e+07
+kurtosis: -0.605406
+skewness: 0.238688
+</pre></div>
 
 
 <h2>SEE ALSO</h2>
 <h2>SEE ALSO</h2>