[GRASS-SVN] r53665 - grass/trunk/vector/v.net

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 2 06:28:03 PDT 2012


Author: mmetz
Date: 2012-11-02 06:28:02 -0700 (Fri, 02 Nov 2012)
New Revision: 53665

Modified:
   grass/trunk/vector/v.net/args.c
   grass/trunk/vector/v.net/connect.c
   grass/trunk/vector/v.net/main.c
   grass/trunk/vector/v.net/proto.h
Log:
v.net: new flag to snap points to network

Modified: grass/trunk/vector/v.net/args.c
===================================================================
--- grass/trunk/vector/v.net/args.c	2012-11-02 13:05:25 UTC (rev 53664)
+++ grass/trunk/vector/v.net/args.c	2012-11-02 13:28:02 UTC (rev 53665)
@@ -83,6 +83,13 @@
     opt->cats_flag->label = _("Assign unique categories to new points");
     opt->cats_flag->description = _("For operation 'nodes'");
     opt->cats_flag->guisection = _("Nodes");
+
+    opt->snap_flag = G_define_flag();
+    opt->snap_flag->key = 's';
+    opt->snap_flag->label = _("Snap points to network");
+    opt->snap_flag->description =
+	_("For operation 'connect'. By default, a new line from the point to the network is created.");
+    opt->snap_flag->guisection = _("Nodes");
 }
 
 void parse_arguments(const struct opt *opt,

Modified: grass/trunk/vector/v.net/connect.c
===================================================================
--- grass/trunk/vector/v.net/connect.c	2012-11-02 13:05:25 UTC (rev 53664)
+++ grass/trunk/vector/v.net/connect.c	2012-11-02 13:28:02 UTC (rev 53665)
@@ -18,10 +18,10 @@
  * \return number of new arcs
  */
 int connect_arcs(struct Map_info *In, struct Map_info *Pnts,
-		 struct Map_info *Out, int nfield, double thresh)
+		 struct Map_info *Out, int nfield, double thresh, int snap)
 {
     int narcs;
-    int type, line, seg, i, ltype;
+    int type, line, seg, i, ltype, broken;
     double px, py, pz, spdist, dist;
 
     struct line_pnts *Points, *Pline, *Pout;
@@ -63,13 +63,17 @@
 	if (seg == 0)
 	    G_fatal_error(_("Failed to find intersection segment"));
 	/* break the line */
+	broken = 0;
 	Vect_reset_line(Pout);
 	for (i = 0; i < seg; i++) {
 	    Vect_append_point(Pout, Pline->x[i], Pline->y[i], Pline->z[i]);
 	}
 	Vect_append_point(Pout, px, py, pz);
 	Vect_line_prune(Pout);
-	Vect_rewrite_line(Out, line, ltype, Pout, Cline);
+	if (Pout->n_points > 1) {
+	    Vect_rewrite_line(Out, line, ltype, Pout, Cline);
+	    broken++;
+	}
 
 	Vect_reset_line(Pout);
 	Vect_append_point(Pout, px, py, pz);
@@ -77,23 +81,40 @@
 	    Vect_append_point(Pout, Pline->x[i], Pline->y[i], Pline->z[i]);
 	}
 	Vect_line_prune(Pout);
-	Vect_write_line(Out, ltype, Pout, Cline);
+	if (Pout->n_points > 1) {
+	    if (broken)
+		Vect_write_line(Out, ltype, Pout, Cline);
+	    else
+		Vect_rewrite_line(Out, line, ltype, Pout, Cline);
+	    broken++;
+	}
+	if (broken == 2)
+	    narcs++;
 
 	if (dist > 0.0) {
-	    /* write new arc */
-	    Vect_reset_line(Pout);
-	    Vect_append_point(Pout, px, py, pz);
-	    Vect_append_point(Pout, Points->x[0], Points->y[0], Points->z[0]);
-	    Vect_write_line(Out, ltype, Pout, Cline);
+	    if (snap) {
+		/* snap point */
+		Points->x[0] = px;
+		Points->y[0] = py;
+		Points->z[0] = pz;
+	    }
+	    else {
+		/* write new arc */
+		Vect_reset_line(Pout);
+		Vect_append_point(Pout, px, py, pz);
+		Vect_append_point(Pout, Points->x[0], Points->y[0], Points->z[0]);
+		Vect_write_line(Out, ltype, Pout, Cline);
+
+		narcs++;
+	    }
 	}
 
 	/* add points to 'nfield' layer */
 	for (i = 0; i < Cats->n_cats; i++) {
 	    Cats->field[i] = nfield;	/* all points to 'nfield' layer */
 	}
+
 	Vect_write_line(Out, type, Points, Cats);
-
-	narcs++;
     }
 
     Vect_destroy_line_struct(Points);

Modified: grass/trunk/vector/v.net/main.c
===================================================================
--- grass/trunk/vector/v.net/main.c	2012-11-02 13:05:25 UTC (rev 53664)
+++ grass/trunk/vector/v.net/main.c	2012-11-02 13:28:02 UTC (rev 53665)
@@ -138,7 +138,8 @@
 	    int narcs;
 
 	    if (act == TOOL_CONNECT)
-		narcs = connect_arcs(In, Points, Out, nfield, thresh);
+		narcs = connect_arcs(In, Points, Out, nfield, thresh,
+		                     opt.snap_flag->answer);
 	    else
 		narcs = create_arcs(file_arcs, Points, Out, afield, nfield);
 

Modified: grass/trunk/vector/v.net/proto.h
===================================================================
--- grass/trunk/vector/v.net/proto.h	2012-11-02 13:05:25 UTC (rev 53664)
+++ grass/trunk/vector/v.net/proto.h	2012-11-02 13:28:02 UTC (rev 53665)
@@ -10,7 +10,7 @@
     struct Option *action;
     struct Option *afield_opt, *nfield_opt, *thresh_opt;
     struct Option *file;
-    struct Flag *cats_flag;
+    struct Flag *cats_flag, *snap_flag;
 };
 
 /* arcs.c */
@@ -24,7 +24,7 @@
 
 /* connect.c */
 int connect_arcs(struct Map_info *, struct Map_info *,
-		 struct Map_info *, int, double);
+		 struct Map_info *, int, double, int);
 
 /* nodes.c */
 int nodes(struct Map_info *, struct Map_info *, int,



More information about the grass-commit mailing list