[GRASS-SVN] r70562 - grass/trunk/vector/v.edit

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Feb 14 04:19:30 PST 2017


Author: hcho
Date: 2017-02-14 04:19:30 -0800 (Tue, 14 Feb 2017)
New Revision: 70562

Modified:
   grass/trunk/vector/v.edit/args.c
   grass/trunk/vector/v.edit/global.h
   grass/trunk/vector/v.edit/main.c
   grass/trunk/vector/v.edit/v.edit.html
Log:
v.edit: Add extend,extendstart,extendend tools with -p flag

These tools are similar to connect, but connect is mainly intended to connect
two lines when the first line can be extended onto the second line. If the
second line is short and extending the first line doesn't intersect the second
one, the minimum distance is not a normal distance and the connect tool can
change the shape of the second line by moving an existing vertex before
connecting two lines. Not sure if that was intended. The extend tools try to
extend both lines until they intersect so that the existing shape doesn't
change. This is important especially for hydrologic analysis such as the
longest flow path on top of the drainage raster map. Since these tools extend
lines to connect them, they don't work for parallel lines by default. Use the
-p flag to add a new node to the first line to connect both lines.



Modified: grass/trunk/vector/v.edit/args.c
===================================================================
--- grass/trunk/vector/v.edit/args.c	2017-02-14 11:59:34 UTC (rev 70561)
+++ grass/trunk/vector/v.edit/args.c	2017-02-14 12:19:30 UTC (rev 70562)
@@ -52,6 +52,9 @@
 	       "snap;%s;"
 	       "flip;%s;"
 	       "connect;%s;"
+	       "extend;%s;"
+	       "extendstart;%s;"
+	       "extendend;%s;"
 	       "zbulk;%s;"
 	       "chtype;%s;"
 	       "areadel;%s",
@@ -73,13 +76,16 @@
 	       _("Snap vector features in given threshold"),
 	       _("Flip direction of selected vector lines"),
 	       _("Connect two lines"),
+	       _("Extend lines"),
+	       _("Extend start nodes"),
+	       _("Extend end nodes"),
 	       _("Z bulk-labeling (automated assignment of z coordinate to "
 		 "vector lines)"),
 	       _("Change feature type (point<->centroid, line<->boundary)"),
 	       _("Delete selected areas from vector map (based on selected centroids)"));
     params->tool->descriptions = desc_tool;
     params->tool->options = "create,add,delete,copy,move,flip,catadd,catdel,"
-	"merge,break,snap,connect,chtype,"
+	"merge,break,snap,connect,extend,extendstart,extendend,chtype,"
 	"vertexadd,vertexdel,vertexmove,areadel,zbulk,select";
 
     params->in = G_define_standard_option(G_OPT_F_INPUT);
@@ -215,6 +221,11 @@
     params->move_first->description =
 	_("Modify only first found feature in bounding box");
 
+    params->extend_parallel = G_define_flag();
+    params->extend_parallel->key = 'p';
+    params->extend_parallel->description =
+	_("Connect parallel lines (using extend tools and threshold distance)");
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
@@ -252,6 +263,15 @@
     else if (strcmp(params->tool->answer, "connect") == 0) {
 	*action_mode = MODE_CONNECT;
     }
+    else if (strcmp(params->tool->answer, "extend") == 0) {
+	*action_mode = MODE_EXTEND;
+    }
+    else if (strcmp(params->tool->answer, "extendstart") == 0) {
+	*action_mode = MODE_EXTEND_START;
+    }
+    else if (strcmp(params->tool->answer, "extendend") == 0) {
+	*action_mode = MODE_EXTEND_END;
+    }
     else if (strcmp(params->tool->answer, "vertexadd") == 0) {
 	*action_mode = MODE_VERTEX_ADD;
     }

Modified: grass/trunk/vector/v.edit/global.h
===================================================================
--- grass/trunk/vector/v.edit/global.h	2017-02-14 11:59:34 UTC (rev 70561)
+++ grass/trunk/vector/v.edit/global.h	2017-02-14 12:19:30 UTC (rev 70562)
@@ -30,6 +30,9 @@
     MODE_MERGE,			/* merge vector lines */
     MODE_BREAK,			/* break (split) vector lines */
     MODE_CONNECT,		/* connect *two* lines */
+    MODE_EXTEND,		/* extend both nodes */
+    MODE_EXTEND_START,		/* extend start node */
+    MODE_EXTEND_END,		/* extend end node */
     MODE_SNAP,			/* snap vector lines */
     /* geometry of feature changed */
     MODE_VERTEX_ADD,		/* add vertex */
@@ -51,7 +54,7 @@
     struct Option *map, *in, *maxdist, *tool,
 	*coord, *cat, *move, *bbox, *fld,
 	*poly, *type, *id, *where, *bmaps, *snap, *query, *zbulk;
-    struct Flag *header, *topo, *close, *reverse, *move_first;
+    struct Flag *header, *topo, *close, *reverse, *move_first, *extend_parallel;
 };
 
 # include "proto.h"

Modified: grass/trunk/vector/v.edit/main.c
===================================================================
--- grass/trunk/vector/v.edit/main.c	2017-02-14 11:59:34 UTC (rev 70561)
+++ grass/trunk/vector/v.edit/main.c	2017-02-14 12:19:30 UTC (rev 70562)
@@ -30,7 +30,7 @@
     FILE *ascii;
 
     int i;
-    int move_first, snap;
+    int move_first, snap, extend_parallel;
     int ret, layer;
     double move_x, move_y, move_z, thresh[3];
 
@@ -196,6 +196,7 @@
     }
 
     move_first = params.move_first->answer ? 1 : 0;
+    extend_parallel = params.extend_parallel->answer ? 1 : 0;
     snap = NO_SNAP;
     if (strcmp(params.snap->answer, "node") == 0)
 	snap = SNAP;
@@ -358,6 +359,33 @@
                      "%d lines connected",
                      ret), ret);
 	break;
+    case MODE_EXTEND:
+	G_verbose_message(_("Threshold value for snapping is %.2f"),
+			  thresh[THRESH_SNAP]);
+	ret = Vedit_extend_lines(&Map, List, 0, extend_parallel,
+				 thresh[THRESH_SNAP]);
+	G_message(n_("%d line extended",
+                     "%d lines extended",
+                     ret), ret);
+	break;
+    case MODE_EXTEND_START:
+	G_verbose_message(_("Threshold value for snapping is %.2f"),
+			  thresh[THRESH_SNAP]);
+	ret = Vedit_extend_lines(&Map, List, 1, extend_parallel,
+				 thresh[THRESH_SNAP]);
+	G_message(n_("%d line extended",
+                     "%d lines extended",
+                     ret), ret);
+	break;
+    case MODE_EXTEND_END:
+	G_verbose_message(_("Threshold value for snapping is %.2f"),
+			  thresh[THRESH_SNAP]);
+	ret = Vedit_extend_lines(&Map, List, 2, extend_parallel,
+				 thresh[THRESH_SNAP]);
+	G_message(n_("%d line extended",
+                     "%d lines extended",
+                     ret), ret);
+	break;
     case MODE_MERGE:
 	ret = Vedit_merge_lines(&Map, List);
 	G_message(n_("%d line merged",

Modified: grass/trunk/vector/v.edit/v.edit.html
===================================================================
--- grass/trunk/vector/v.edit/v.edit.html	2017-02-14 11:59:34 UTC (rev 70561)
+++ grass/trunk/vector/v.edit/v.edit.html	2017-02-14 12:19:30 UTC (rev 70562)
@@ -121,6 +121,20 @@
     between them is not greater than snapping threshold
     distance <b>threshold</b>.</li>
 
+    <li><b>extend</b> - Extend selected lines or boundaries without changing
+    the current shape. Similar to <b>connect</b>, but the first and second
+    lines are both extended until they intersect. The second line is broken if
+    necessary. The lines are extended only if distance between them is not
+    greater than snapping threshold distance <b>threshold</b>. If the first and
+    second lines are parallel and do not intersect, no lines are extended. Use
+    the <b>-p</b> flag to extend the first line across the parallel gap.</li>
+
+    <li><b>extendstart</b> - Similar to <b>extend</b>, but extend start nodes
+    only.</li>
+
+    <li><b>extendend</b> - Similar to <b>extend</b>, but extend end nodes
+    only.</li>
+
     <li><b>chtype</b> - Change feature type of selected geometry
     objects. Points are converted to centroids, centroids to points,
     lines to boundaries and boundaries to lines.



More information about the grass-commit mailing list