[GRASS-SVN] r46935 - grass/branches/develbranch_6/vector/v.build.polylines

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jul 3 10:25:43 EDT 2011


Author: mmetz
Date: 2011-07-03 07:25:43 -0700 (Sun, 03 Jul 2011)
New Revision: 46935

Modified:
   grass/branches/develbranch_6/vector/v.build.polylines/description.html
   grass/branches/develbranch_6/vector/v.build.polylines/main.c
   grass/branches/develbranch_6/vector/v.build.polylines/walk.c
   grass/branches/develbranch_6/vector/v.build.polylines/walk.h
Log:
do not mix lines and boundaries (backport from trunk r46934

Modified: grass/branches/develbranch_6/vector/v.build.polylines/description.html
===================================================================
--- grass/branches/develbranch_6/vector/v.build.polylines/description.html	2011-07-03 14:25:04 UTC (rev 46934)
+++ grass/branches/develbranch_6/vector/v.build.polylines/description.html	2011-07-03 14:25:43 UTC (rev 46935)
@@ -4,18 +4,17 @@
 boundaries in a vector map.
 
 <p>
-A line is a single straight line segment defined by one start node, one end 
-node and no other nodes. A polyline is also defined by one start node, one end 
-node and no other nodes, but is made of two or more consecutive straight line 
-segments. The connections between the constituent line segments of a polyline 
-do not appear as nodes in the vector map.
+A line is defined by one start node, one end node and any number of
+vertices between the start and end node. The shortest possible line
+consists of only two vertices where the coordinates of the start and end
+node are identical to those of the two vertices.
 
 <p>
 <em>v.build.polyline</em> picks a line and from its start node, walks
-back as long as exactly one other line is connected to this node. Line
-directions are reversed as required, i.e. it does not matter if the
-next line is connected to the current node by its start or end
-node. Once the start line of a polyline is identified, it walks
+back as long as exactly one other line of the same type is connected to
+this node. Line directions are reversed as required, i.e. it does not
+matter if the next line is connected to the current node by its start or
+end node. Once the start line of a polyline is identified, it walks
 forward and adds all vertices (in reverse order if needed) of
 connected lines to the start line, i.e. the start line and connecting
 lines are reversed as needed. That is, if a line is reversed depends
@@ -36,8 +35,8 @@
 
 <h2>NOTES</h2>
 
-If the lines that make up a polyline are of different types, then 
-<em>v.build.polylines</em> will set the type from the first constituent line.  
+<em>v.build.polylines</em> combines only lines oif the same type to
+a new polyline, i.e. lines and boundaries are kept separate.
 
 <p>
 Category number(s) are assigned to a polyline based on <b>cats</b> parameter.
@@ -57,9 +56,8 @@
 
 <em>v.build.polylines</em> correctly handles <b>input</b> vector maps
 containing lines, boundaries, centroids and points. Lines and
-boundaries will be converted to polylines of the desired type.  Areas
-are only guaranteed to be preserved if the constituent lines of the
-polylines that define them are all boundaries in the input vector map.
+boundaries will be converted to polylines.  Areas
+are guaranteed to be preserved.
 
 <!-- Points will remain points provided that <b>type</b> has been set
 to `source'.  It is possible to convert lines and area edges to points
@@ -83,7 +81,8 @@
 <h2>AUTHORS</h2>
 Mark Lake, Institute of Archaeology, University College London.<br> 
 Major rewrite by Radim Blazek, October 2002<br>
-Category mode added by Martin Landa, FBK-irst, Trento, Italy, October 2007
+Category mode added by Martin Landa, FBK-irst, Trento, Italy, October 2007<br>
+Support for different line types by Markus Metz
 
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/vector/v.build.polylines/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.build.polylines/main.c	2011-07-03 14:25:04 UTC (rev 46934)
+++ grass/branches/develbranch_6/vector/v.build.polylines/main.c	2011-07-03 14:25:43 UTC (rev 46935)
@@ -6,8 +6,9 @@
  *               Major rewrite by Radim Blazek, October 2002
  *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
  *               Martin Landa <landa.martin gmail.com> (cats)
+ *               Markus Metz (geometry type management)
  * PURPOSE:      
- * COPYRIGHT:    (C) 2002-2007 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2011 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
@@ -89,17 +90,18 @@
     struct Option *input;
     struct Option *output;
     struct Option *cats;
+    struct Option *type_opt;
     struct Flag *quietly;
 
     int polyline;
     int *lines_visited;
     int points_in_polyline;
     int start_line;
-    int nlines, type;
+    int nlines;
     int write_cats;
 
     char *mapset;
-    int start_type;
+    int type, ltype;
 
     /*  Initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -123,6 +125,10 @@
 			   "multi;Assign multiple category numbers to polyline");
     cats->answer = "no";
 
+    type_opt = G_define_standard_option(G_OPT_V_TYPE);
+    type_opt->options = "line,boundary";
+    type_opt->answer = "line,boundary";
+
     quietly = G_define_flag();
     quietly->key = 'q';
     quietly->description = _("Unused");
@@ -168,20 +174,25 @@
     else
 	write_cats = MULTI_CATS;
 
+    if (type_opt->answer)
+	Vect_option_to_types(type_opt);
+    else
+	type = GV_LINES;
+
     /* Step over all lines in binary map */
     polyline = 0;
     nlines = 0;
 
     for (line = 1; line <= Vect_get_num_lines(&map); line++) {
 	Vect_reset_cats(Cats);
-	type = Vect_read_line(&map, NULL, NULL, line);
+	ltype = Vect_read_line(&map, NULL, NULL, line);
 
-	if (type & GV_LINES)
+	if ((ltype & GV_LINES) && (ltype & type))
 	    nlines++;
 	else {
 	    /* copy points to output as they are, with cats */
 	    Vect_read_line(&map, points, Cats, line);
-	    Vect_write_line(&Out, type, points, Cats);
+	    Vect_write_line(&Out, ltype, points, Cats);
 	    continue;
 	}
 
@@ -192,21 +203,19 @@
 	/* Only get here if line is not previously visited */
 
 	/* Find start of this polyline */
-	start_line = walk_back(&map, line);
-	start_type = Vect_read_line(&map, NULL, NULL, start_line);
+	start_line = walk_back(&map, line, ltype);
 
-	G_debug(1, "Polyline %d: start line = %d \n", polyline, start_line);
+	G_debug(1, "Polyline %d: start line = %d", polyline, start_line);
 
 	/* Walk forward and pick up coordinates */
 	points_in_polyline =
-	    walk_forward_and_pick_up_coords(&map, start_line, points,
+	    walk_forward_and_pick_up_coords(&map, start_line, ltype, points,
 					    lines_visited, Cats, write_cats);
 
 	/* Write the line (type of the first line is used) */
-	Vect_write_line(&Out, start_type, points, Cats);
+	Vect_write_line(&Out, ltype, points, Cats);
 
-	if (type & GV_LINES)
-	    polyline++;
+	polyline++;
     }
 
     G_message(_("%d lines or boundaries found in vector map <%s@%s>"),

Modified: grass/branches/develbranch_6/vector/v.build.polylines/walk.c
===================================================================
--- grass/branches/develbranch_6/vector/v.build.polylines/walk.c	2011-07-03 14:25:04 UTC (rev 46934)
+++ grass/branches/develbranch_6/vector/v.build.polylines/walk.c	2011-07-03 14:25:43 UTC (rev 46935)
@@ -7,7 +7,7 @@
  *  return: next line (may be input line if it is loop)
  *          0 - num of lines <> 2
  */
-int find_next_line(struct Map_info *map, int line, int node)
+int find_next_line(struct Map_info *map, int line, int node, int ltype)
 {
     int n_lines, i, tmp_line, tmp_type, next_line;
 
@@ -18,7 +18,7 @@
 	tmp_line = abs(Vect_get_node_line(map, node, i));
 	tmp_type = Vect_read_line(map, NULL, NULL, tmp_line);
 	/* The line may be a loop so we want some other line if exists or the same line if loop */
-	if (tmp_type & GV_LINES) {
+	if (tmp_type & ltype) {
 	    if (next_line == 0 || tmp_line != line)
 		next_line = tmp_line;
 	    n_lines++;
@@ -36,28 +36,21 @@
    This line must not be a dead line (note that the arbitrary line
    cannot be a dead line because this has already been checked in
    main.c. */
-int walk_back(struct Map_info *map, int start_line)
+int walk_back(struct Map_info *map, int start_line, int type)
 {
     int start_node, n1, n2;
     int line;
     int next_line;
-    int type;
 
     G_debug(2, "walk_back() start = %d", start_line);
     line = start_line;
 
-    /* By definition a GV_POINT and GV_CENTROID does not form part of a longer polyline, so
-       this line must be the start */
-    type = Vect_read_line(map, NULL, NULL, line);
-    if (type == GV_POINT || type == GV_CENTROID)
-	return (line);
-
     /* Otherwise find the start (i.e. travel in the negative direction) */
     Vect_get_line_nodes(map, line, &start_node, NULL);
 
     while (1) {
 	/* Find next line at start node */
-	next_line = find_next_line(map, line, start_node);
+	next_line = find_next_line(map, line, start_node, type);
 	G_debug(2, "  next = %d", next_line);
 
 	/* Keep going so long as not returned to start_line, i.e. if not a closed set of lines */
@@ -84,7 +77,7 @@
 /* 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,
-				    int start_line,
+				    int start_line, int ltype,
 				    struct line_pnts *points,
 				    int *lines_visited,
 				    struct line_cats *Cats, int write_cats)
@@ -115,14 +108,14 @@
 	type = Vect_read_line(map, pnts, NULL, line);
 
     Vect_get_line_nodes(map, line, &n1, &n2);
-    next_line = find_next_line(map, line, n1);
+    next_line = find_next_line(map, line, n1, ltype);
     if (next_line > 0) {	/* continue at start node */
 	Vect_append_points(points, pnts, GV_BACKWARD);
 	next_node = n1;
     }
     else {
 	Vect_append_points(points, pnts, GV_FORWARD);
-	next_line = find_next_line(map, line, n2);	/* check end node */
+	next_line = find_next_line(map, line, n2, ltype);	/* check end node */
 	if (next_line > 0) {
 	    next_node = n2;	/* continue at end node */
 	}
@@ -131,10 +124,6 @@
 	}
     }
 
-    /* This line can only be part of a longer polyline if it is not a point.  */
-    if (type & GV_POINTS)
-	return 1;
-
     /* While next line exist append coordinates */
     line = next_line;
     node = next_node;
@@ -163,7 +152,7 @@
 	lines_visited[line] = 1;
 
 	/* Find next one */
-	next_line = find_next_line(map, line, next_node);
+	next_line = find_next_line(map, line, next_node, ltype);
 
 	line = next_line;
 	node = next_node;

Modified: grass/branches/develbranch_6/vector/v.build.polylines/walk.h
===================================================================
--- grass/branches/develbranch_6/vector/v.build.polylines/walk.h	2011-07-03 14:25:04 UTC (rev 46934)
+++ grass/branches/develbranch_6/vector/v.build.polylines/walk.h	2011-07-03 14:25:43 UTC (rev 46935)
@@ -2,7 +2,7 @@
 #define ONE_CAT     1
 #define MULTI_CATS  2
 
-int walk_back(struct Map_info *, int);
-int walk_forward_and_pick_up_coords(struct Map_info *, int,
+int walk_back(struct Map_info *, int, int);
+int walk_forward_and_pick_up_coords(struct Map_info *, int, int,
 				    struct line_pnts *, int *,
 				    struct line_cats *, int);



More information about the grass-commit mailing list