[GRASS-SVN] r67753 - grass/trunk/vector/v.build.polylines

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 7 02:43:06 PST 2016


Author: turek
Date: 2016-02-07 02:43:05 -0800 (Sun, 07 Feb 2016)
New Revision: 67753

Modified:
   grass/trunk/vector/v.build.polylines/main.c
   grass/trunk/vector/v.build.polylines/v.build.polylines.html
   grass/trunk/vector/v.build.polylines/walk.c
   grass/trunk/vector/v.build.polylines/walk.h
Log:
v.build.polylines: added cats=same option

Modified: grass/trunk/vector/v.build.polylines/main.c
===================================================================
--- grass/trunk/vector/v.build.polylines/main.c	2016-02-06 20:54:19 UTC (rev 67752)
+++ grass/trunk/vector/v.build.polylines/main.c	2016-02-07 10:43:05 UTC (rev 67753)
@@ -125,13 +125,14 @@
     cats->key = "cats";
     cats->type = TYPE_STRING;
     cats->description = _("Category number mode");
-    cats->options = "no,first,multi";
+    cats->options = "no,first,multi,same";
     desc = NULL;
     G_asprintf(&desc,
-	       "no;%s;first;%s;multi;%s",
+	       "no;%s;first;%s;multi;%ssame;%s",
 	       _("Do not assign any category number to polyline"),
 	       _("Assign category number of first line to polyline"),
-	       _("Assign multiple category numbers to polyline"));
+	       _("Assign multiple category numbers to polyline"),
+	       _("Create polyline from lines with same categories"));
     cats->descriptions = desc;
     cats->answer = "no";
 

Modified: grass/trunk/vector/v.build.polylines/v.build.polylines.html
===================================================================
--- grass/trunk/vector/v.build.polylines/v.build.polylines.html	2016-02-06 20:54:19 UTC (rev 67752)
+++ grass/trunk/vector/v.build.polylines/v.build.polylines.html	2016-02-07 10:43:05 UTC (rev 67753)
@@ -49,6 +49,9 @@
   different category numbers then <em>v.build.polylines</em> will
   set the multiple category numbers to a polyline.  Also all linked
   attributes tables are copied to the output vector map.</li>
+  <li><b>cats=same</b> - Assigned lines to a polyline have
+  same category numbers in all layers. Linked
+  attributes tables are copied to the output vector map.</li>
 </ul>
 
 <em>v.build.polylines</em> correctly handles <b>input</b> vector maps

Modified: grass/trunk/vector/v.build.polylines/walk.c
===================================================================
--- grass/trunk/vector/v.build.polylines/walk.c	2016-02-06 20:54:19 UTC (rev 67752)
+++ grass/trunk/vector/v.build.polylines/walk.c	2016-02-07 10:43:05 UTC (rev 67753)
@@ -74,6 +74,51 @@
     return (line);
 }
 
+/* 
+   \brief Compare two line_cats structs.
+
+   \return 1 - structs have same categories in all fields
+   \return 0 - structs do not have same categories in all fields
+ */
+int cmp_cats(struct line_cats *Cats1, struct line_cats *Cats2)
+{
+    int cat_found, cat_idx, i, ret;
+    struct ilist *cats_list;
+
+    if (Cats1->n_cats != Cats2->n_cats) {
+	return 0;
+    }
+
+    cats_list = Vect_new_list();
+
+    for (cat_idx = 0; cat_idx < Cats1->n_cats; cat_idx++) {
+
+	ret = Vect_field_cat_get(Cats2, Cats1->field[cat_idx], cats_list);
+
+	if (ret == -1) {
+	    Vect_destroy_list(cats_list);
+	    return 0;
+	}
+
+	cat_found = 0;
+
+	for (i = 0; i < cats_list->n_values; i++) {
+	    if (Cats1->cat[cat_idx] == cats_list->value[i]) {
+		cat_found = 1;
+	    }
+
+	}
+
+	if (cat_found == 0) {
+	    Vect_destroy_list(cats_list);
+	    return 0;
+	}
+    }
+
+    Vect_destroy_list(cats_list);
+    return 1;
+}
+
 /* Start from the first node on a polyline and walk to the other end,
    collecting the coordinates of each node en route.  */
 int walk_forward_and_pick_up_coords(struct Map_info *map,
@@ -137,6 +182,14 @@
 			     cats_tmp->cat[cat_idx]);
 	    }
 	}
+
+	if (cats_tmp && write_cats == SAME_CATS) {
+
+	    if (cmp_cats(Cats, cats_tmp) == 0) {
+		break;
+	    }
+	}
+
 	Vect_get_line_nodes(map, line, &n1, &n2);
 
 	if (node == n1) {

Modified: grass/trunk/vector/v.build.polylines/walk.h
===================================================================
--- grass/trunk/vector/v.build.polylines/walk.h	2016-02-06 20:54:19 UTC (rev 67752)
+++ grass/trunk/vector/v.build.polylines/walk.h	2016-02-07 10:43:05 UTC (rev 67753)
@@ -1,7 +1,9 @@
 #define NO_CATS     0
 #define ONE_CAT     1
 #define MULTI_CATS  2
+#define SAME_CATS   3
 
+
 int walk_back(struct Map_info *, int, int);
 int walk_forward_and_pick_up_coords(struct Map_info *, int, int,
 				    struct line_pnts *, int *,



More information about the grass-commit mailing list