Sfoglia il codice sorgente

v.to.db: fix report (don't report features without category)
(merge from devbr6, https://trac.osgeo.org/grass/changeset/34807)


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

Martin Landa 16 anni fa
parent
commit
d814680ac1

+ 2 - 2
vector/v.to.db/areas.c

@@ -47,7 +47,7 @@ int read_areas(struct Map_info *Map)
 	if (Vect_get_area_cats(Map, area_num, Cats) == 0) {
 	    for (i = 0; i < Cats->n_cats; i++) {
 		if (Cats->field[i] == options.field) {
-		    idx = find_cat(Cats->cat[i]);
+		    idx = find_cat(Cats->cat[i], 1);
 		    switch (options.option) {
 		    case O_AREA:
 			Values[idx].d1 += area;
@@ -68,7 +68,7 @@ int read_areas(struct Map_info *Map)
 	    }
 	    /* why do we do this? */
 	    if (!found) {	/* no category found */
-		idx = find_cat(0);
+		idx = find_cat(0, 1);
 		if (options.option == O_AREA) {
 		    Values[idx].d1 += area;
 		}

+ 4 - 1
vector/v.to.db/find.c

@@ -3,7 +3,7 @@
 #include  "global.h"
 
 /* returns index to array of values, inserts new if necessary */
-int find_cat(int cat)
+int find_cat(int cat, int add)
 {
     int i;
 
@@ -11,6 +11,9 @@ int find_cat(int cat)
 	if (Values[i].cat == cat)
 	    return i;
 
+    if (!add)
+	return -1;
+
     /* Not found -> add new */
     Values[vstat.rcat].cat = cat;
     Values[vstat.rcat].count1 = 0;

+ 1 - 1
vector/v.to.db/global.h

@@ -82,7 +82,7 @@ int read_areas(struct Map_info *);
 double length(register int, register double *, register double *);
 
 /* find.c */
-int find_cat(int);
+int find_cat(int, int);
 
 /* line.c */
 int read_lines(struct Map_info *);

+ 2 - 2
vector/v.to.db/lines.c

@@ -115,7 +115,7 @@ int read_lines(struct Map_info *Map)
 
 	for (i = 0; i < Cats->n_cats; i++) {
 	    if (Cats->field[i] == options.field) {
-		idx = find_cat(Cats->cat[i]);
+		idx = find_cat(Cats->cat[i], 1);
 		if (options.option == O_COUNT) {
 		    Values[idx].count1++;
 		}
@@ -198,7 +198,7 @@ int read_lines(struct Map_info *Map)
 	}
 
 	if (!found) {		/* Values for no category (cat = -1) are reported at the end */
-	    idx = find_cat(-1);
+	    idx = find_cat(-1, 1);
 	    if (options.option == O_COUNT) {
 		Values[idx].count1++;
 	    }

+ 3 - 3
vector/v.to.db/main.c

@@ -91,12 +91,12 @@ int main(int argc, char *argv[])
 
     Vect_close(&Map);
 
-    /* free list */
-    G_free(Values);
-
     if (!(options.print && options.total)) {
 	print_stat();
     }
 
+    /* free list */
+    G_free(Values);
+
     exit(EXIT_SUCCESS);
 }

+ 2 - 2
vector/v.to.db/query.c

@@ -34,7 +34,7 @@ int query(struct Map_info *Map)
 
 		cat_no = Cats->cat[i];
 
-		idx = find_cat(cat_no);
+		idx = find_cat(cat_no, 1);
 
 		for (j = 0; j < Cats->n_cats; j++) {
 		    if (Cats->field[j] == options.qfield) {	/* Add to list */
@@ -56,7 +56,7 @@ int query(struct Map_info *Map)
 	Vect_cat_get(Cats, options.field, &cat_no);
 
 	if (cat_no == -1) {
-	    idx = find_cat(cat_no);
+	    idx = find_cat(cat_no, 1);
 
 	    for (j = 0; j < Cats->n_cats; j++) {
 		if (Cats->field[j] == options.qfield) {	/* Add to list */

+ 9 - 2
vector/v.to.db/report.c

@@ -171,9 +171,16 @@ int report(void)
 
 int print_stat(void)
 {
-    if (vstat.rcat > 0)
+    if (vstat.rcat > 0) {
+	int rcat_report;
+	if(find_cat(-1, 0) != -1)
+	    rcat_report = vstat.rcat - 1;
+	else
+	    rcat_report = vstat.rcat;
+	
 	G_message(_("%d categories read from vector map (layer %d)"),
-		  vstat.rcat - 1, options.field); /* don't report cat -1 */
+		  rcat_report, options.field); /* don't report cat -1 */
+    }
     if (vstat.select > 0)
 	G_message(_("%d records selected from table (layer %d)"),
 		  vstat.select, options.qfield);