[GRASS-SVN] r50501 - grass/trunk/vector/v.category

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 27 13:10:35 EST 2012


Author: huhabla
Date: 2012-01-27 10:10:35 -0800 (Fri, 27 Jan 2012)
New Revision: 50501

Modified:
   grass/trunk/vector/v.category/main.c
   grass/trunk/vector/v.category/v.category.html
Log:
Enabled multi-layer transfer


Modified: grass/trunk/vector/v.category/main.c
===================================================================
--- grass/trunk/vector/v.category/main.c	2012-01-27 16:55:15 UTC (rev 50500)
+++ grass/trunk/vector/v.category/main.c	2012-01-27 18:10:35 UTC (rev 50501)
@@ -102,7 +102,7 @@
 				 "del;delete category (-1 to delete all categories of given layer);"
 				 "chlayer;change layer number (e.g. layer=3,1 changes layer 3 to layer 1);"
 				 "sum;add the value specified by cat option to the current category value;"
-				 "transfer;copy values from one layer to another (e.g. layer=1,2 copies values from layer 1 to layer 2);"
+				 "transfer;copy values from one layer to another (e.g. layer=1,2,3 copies values from layer 1 to layer 2 and 3);"
 				 "report;print report (statistics), in shell style: layer type count min max;"
 				 "print;print category values, more cats in the same layer are separated by '/'");
     
@@ -233,10 +233,12 @@
     }
 
     if (option == O_TRANS && open_level > 1) {
-	/* check if field[1] already exists */
+	/* check if field[>0] already exists */
 	if (nfields > 1) {
-	    if (Vect_cidx_get_field_index(&In, fields[1]) != -1)
-		G_warning(_("Categories already exist in layer %d"), fields[1]);
+	    for(i = 1; i < nfields; i++) {
+		if (Vect_cidx_get_field_index(&In, fields[i]) != -1)
+		    G_warning(_("Categories already exist in layer %d"), fields[i]);
+	    }
 	}
 	/* find next free layer number */
 	else if (nfields == 1) {
@@ -339,11 +341,15 @@
 		for (i = 0; i < n; i++) {
 		    if (Cats->field[i] == fields[0]) {
 			scat = Cats->cat[i];
-			if (Vect_cat_set(Cats, fields[1], scat) > 0) {
-			    nmodified++;
-			}
+			break;
 		    }
 		}
+		for (i = 1; i < nfields; i++) {
+		    if (Vect_cat_set(Cats, fields[i], scat) > 0) {
+			G_debug(4, "Copy cat %i of field %i to into field %i", scat, fields[0], fields[i]);
+		    }
+		}
+		nmodified++;
 	    }
 	    Vect_write_line(&Out, type, Points, Cats);
 	}
@@ -703,8 +709,9 @@
 	Vect_close(&Out);
 
 	if (option == O_TRANS && nmodified > 0)
-	    G_important_message(_("Categories copied from layer %d to layer %d"),
-				fields[0], fields[1]);
+	    for(i = 0; i < nfields; i++)
+		G_important_message(_("Categories copied from layer %d to layer %d"),
+				fields[0], fields[i]);
 	G_done_msg(_("%d features modified."), nmodified);
     }
     Vect_close(&In);

Modified: grass/trunk/vector/v.category/v.category.html
===================================================================
--- grass/trunk/vector/v.category/v.category.html	2012-01-27 16:55:15 UTC (rev 50500)
+++ grass/trunk/vector/v.category/v.category.html	2012-01-27 18:10:35 UTC (rev 50501)
@@ -102,6 +102,12 @@
 Results can be tested
 using <em><a href="d.what.vect.html">d.what.vect</a></em>.
 
+<h3>Copy categories from layer 1 to layer 2,3,4,5,6,7 and 8</h3>
+Existing layer will be overwritten, non-existing will be created.
+<div class="code"><pre>
+v.category input=observer output=observer_new option=transfer layer=1,2,3,4,5,6,7,8
+</pre></div>
+
 <h3>Print vector categories of given layer</h3>
 
 Print vector categories from the first layer, only for feature ids 1-50.



More information about the grass-commit mailing list