[GRASS-SVN] r74283 - grass/trunk/vector/v.to.points

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 17 12:45:18 PDT 2019


Author: martinl
Date: 2019-03-17 12:45:18 -0700 (Sun, 17 Mar 2019)
New Revision: 74283

Modified:
   grass/trunk/vector/v.to.points/local_proto.h
   grass/trunk/vector/v.to.points/main.c
   grass/trunk/vector/v.to.points/v.to.points.html
   grass/trunk/vector/v.to.points/write.c
Log:
v.to.points: new option use=start/end [news]

Modified: grass/trunk/vector/v.to.points/local_proto.h
===================================================================
--- grass/trunk/vector/v.to.points/local_proto.h	2019-03-17 12:28:31 UTC (rev 74282)
+++ grass/trunk/vector/v.to.points/local_proto.h	2019-03-17 19:45:18 UTC (rev 74283)
@@ -1,6 +1,8 @@
 #ifndef __LOCAL_PROTO_H
 #define GV_NODE   1
 #define GV_VERTEX 2
+#define GV_START  3
+#define GV_END    4
 
 void write_point(struct Map_info *, double, double, double,
 		 int, double, dbDriver *, struct field_info *);

Modified: grass/trunk/vector/v.to.points/main.c
===================================================================
--- grass/trunk/vector/v.to.points/main.c	2019-03-17 12:28:31 UTC (rev 74282)
+++ grass/trunk/vector/v.to.points/main.c	2019-03-17 19:45:18 UTC (rev 74283)
@@ -8,7 +8,7 @@
  *               
  * PURPOSE:      Create points along lines 
  *               
- * COPYRIGHT:    (C) 2002-2017 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2019 by the GRASS Development Team
  *
  *               This program is free software under the GNU General
  *               Public License (>=v2).  Read the file COPYING that
@@ -76,8 +76,8 @@
     opt.use->key = "use";
     opt.use->type = TYPE_STRING;
     opt.use->required = NO;
-    opt.use->description = _("Use line nodes or vertices only");
-    opt.use->options = "node,vertex";
+    opt.use->description = _("Use line nodes (start/end) or vertices only");
+    opt.use->options = "node,start,end,vertex";
 
     opt.dmax = G_define_option();
     opt.dmax->key = "dmax";
@@ -114,12 +114,32 @@
 
     vertex_type = 0;
     if (opt.use->answer) {
-        if (opt.use->answer[0] == 'n')
+        switch (opt.use->answer[0]) {
+        case 'n':
             vertex_type = GV_NODE;
-        else
+            break;
+        case 's':
+            vertex_type = GV_START;
+            break;
+        case 'e':
+            vertex_type = GV_END;
+            break;
+        default:
             vertex_type = GV_VERTEX;
+            break;
+        }
     }
-    
+
+    if (flag.inter->answer && vertex_type != GV_VERTEX) {
+        G_warning(_("Flag -%c ignored (requires %s=%s)"), flag.inter->key,
+                  opt.use->key, "vertex");
+        flag.inter->answer = FALSE;
+    }
+    if (flag.reverse->answer && (vertex_type == GV_START || vertex_type == GV_END)) {
+        G_warning(_("Flag -%c ignored (reason %s=%s)"), flag.reverse->key,
+                  opt.use->key, opt.use->answer);
+        flag.reverse->answer = FALSE;
+    }
     Vect_check_input_output_name(opt.input->answer, opt.output->answer,
 				 G_FATAL_EXIT);
 

Modified: grass/trunk/vector/v.to.points/v.to.points.html
===================================================================
--- grass/trunk/vector/v.to.points/v.to.points.html	2019-03-17 12:28:31 UTC (rev 74282)
+++ grass/trunk/vector/v.to.points/v.to.points.html	2019-03-17 19:45:18 UTC (rev 74283)
@@ -67,7 +67,7 @@
 The <b>use=vertex</b> option is used to digitize points that fall on
 the line's vertices <em>only</em>. Parameter <b>dmax</b> is ignored in
 this case. Similarly to <b>use=node</b> when only line's node are
-used.
+used. To filter only starting/ending nodes use <b>use=start/end</b>.
 
 <p>
 If the <b>-i</b> flag is used in conjunction with the <b>use=vertex</b> option,

Modified: grass/trunk/vector/v.to.points/write.c
===================================================================
--- grass/trunk/vector/v.to.points/write.c	2019-03-17 12:28:31 UTC (rev 74282)
+++ grass/trunk/vector/v.to.points/write.c	2019-03-17 19:45:18 UTC (rev 74283)
@@ -78,7 +78,7 @@
 			       double dmax, dbDriver *driver,
 			       struct field_info *Fi)
 {
-    if (vertex == GV_VERTEX || vertex == GV_NODE) {	/* use line vertices */
+    if (vertex != 0) {	/* use line vertices */
 	double along;
 	int vert;
 
@@ -86,14 +86,17 @@
 	for (vert = 0; vert < LPoints->n_points; vert++) {
 	    G_debug(3, "vert = %d", vert);
 
-	    if (vertex == GV_VERTEX ||
-		(vertex == GV_NODE &&
-		 (vert == 0 || vert == LPoints->n_points - 1))) {
-		if (vert == LPoints->n_points - 1)
-		    along = Vect_line_length(LPoints);
-		write_point(Out, LPoints->x[vert], LPoints->y[vert],
-			    LPoints->z[vert], cat, along, driver, Fi);
-	    }
+            if (vertex == GV_NODE && (vert > 0 && vert < LPoints->n_points - 1))
+                continue;
+            if (vertex == GV_START && vert > 0)
+                return;
+            if (vertex == GV_END && vert < LPoints->n_points - 1)
+                continue;
+            
+            if (vert == LPoints->n_points - 1)
+                along = Vect_line_length(LPoints);
+            write_point(Out, LPoints->x[vert], LPoints->y[vert],
+                        LPoints->z[vert], cat, along, driver, Fi);
 
 	    if (vert < LPoints->n_points - 1) {
 		double dx, dy, dz, len;



More information about the grass-commit mailing list