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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 5 14:25:33 PST 2016


Author: mmetz
Date: 2016-03-05 14:25:33 -0800 (Sat, 05 Mar 2016)
New Revision: 68005

Modified:
   grass/trunk/vector/v.net.components/main.c
   grass/trunk/vector/v.net.components/v.net.components.html
Log:
v.net.components: various bug fixes

Modified: grass/trunk/vector/v.net.components/main.c
===================================================================
--- grass/trunk/vector/v.net.components/main.c	2016-03-05 10:15:36 UTC (rev 68004)
+++ grass/trunk/vector/v.net.components/main.c	2016-03-05 22:25:33 UTC (rev 68005)
@@ -4,6 +4,7 @@
  * MODULE:     v.net.components
  *
  * AUTHOR(S):  Daniel Bundala
+ *             Markus Metz
  *
  * PURPOSE:    Computes strongly and weakly connected components
  *
@@ -54,7 +55,7 @@
     int with_z;
     int afield, nfield, mask_type;
     dglGraph_s *graph;
-    int *component, nnodes, type, i, nlines, components, j, max_cat;
+    int *component, nnodes, type, i, nlines, components, max_cat;
     char buf[2000], *covered;
     char *desc;
 
@@ -158,7 +159,7 @@
     nfield = Vect_get_field_number(&In, nfield_opt->answer);
 
     if (0 != Vect_net_build_graph(&In, mask_type, afield, nfield, afcol->answer,
-                                  abcol->answer, ncol->answer, 0, 0))
+                                  abcol->answer, ncol->answer, 0, 2))
         G_fatal_error(_("Unable to build graph for vector map <%s>"), Vect_get_full_name(&In));
 
     graph = Vect_net_get_graph(&In);
@@ -198,21 +199,30 @@
 
     db_begin_transaction(driver);
 
-    if (method_opt->answer[0] == 'w')
+    if (method_opt->answer[0] == 'w') {
+	G_message(_("Computing weakly connected components..."));
 	components = NetA_weakly_connected_components(graph, component);
-    else
+    }
+    else {
+	G_message(_("Computing strongly connected components..."));
 	components = NetA_strongly_connected_components(graph, component);
+    }
 
     G_debug(3, "Components: %d", components);
 
+    G_message(_("Writing output..."));
+
     Vect_copy_head_data(&In, &Out);
     Vect_hist_copy(&In, &Out);
     Vect_hist_command(&Out);
 
     nlines = Vect_get_num_lines(&In);
+    max_cat = 1;
+    G_percent(0, nlines, 4);
     for (i = 1; i <= nlines; i++) {
 	int comp, cat;
 
+	G_percent(i, nlines, 4);
 	type = Vect_read_line(&In, Points, Cats, i);
 	if (!Vect_cat_get(Cats, afield, &cat))
 	    continue;
@@ -232,29 +242,23 @@
 
 	    /* Vect_get_line_nodes(&In, i, &node, NULL); */
 	    node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	    if (!node)
+		continue;
 	    comp = component[node];
 	    covered[node] = 1;
 	}
 	else
 	    continue;
+	
+	cat = max_cat++;
+	Vect_reset_cats(Cats);
+	Vect_cat_set(Cats, 1, cat);
 	Vect_write_line(&Out, type, Points, Cats);
 	insert_new_record(driver, Fi, &sql, cat, comp);
-	/*        for(j=0;j<Cats->n_cats;j++)
-	 * if(Cats->field[j] == layer)
-	 * insert_new_record(driver, Fi, &sql, Cats->cat[j], comp);
-	 */
-    };
+    }
+
     /*add points on nodes not covered by any point in the network */
-    /*find the maximum cat number */
     if (add_f->answer) {
-	max_cat = 0;
-	for (i = 1; i <= nlines; i++) {
-	    Vect_read_line(&In, NULL, Cats, i);
-	    for (j = 0; j < Cats->n_cats; j++)
-		if (Cats->cat[j] > max_cat)
-		    max_cat = Cats->cat[j];
-	}
-	max_cat++;
 	for (i = 1; i <= nnodes; i++)
 	    if (!covered[i]) {
 		Vect_reset_cats(Cats);
@@ -267,10 +271,12 @@
     db_commit_transaction(driver);
     db_close_database_shutdown_driver(driver);
 
+    Vect_close(&In);
+
     Vect_build(&Out);
-
-    Vect_close(&In);
     Vect_close(&Out);
 
+    G_done_msg(_("Found %d components."), components);
+
     exit(EXIT_SUCCESS);
 }

Modified: grass/trunk/vector/v.net.components/v.net.components.html
===================================================================
--- grass/trunk/vector/v.net.components/v.net.components.html	2016-03-05 10:15:36 UTC (rev 68004)
+++ grass/trunk/vector/v.net.components/v.net.components.html	2016-03-05 22:25:33 UTC (rev 68005)
@@ -4,22 +4,28 @@
 components in a network.
 
 <h2>NOTES</h2>
-Two nodes, <em>u</em> and <em>v</em> are in the same strongly 
-connected component if there are directed paths from <em>u</em> to 
-<em>v</em> and from <em>v</em> to <em>u</em>. The nodes are in the 
-same weakly connected component if, ignoring orientation of the 
-edges, there is a path between them.
-<br>
-
+Two nodes, <em>u</em> and <em>v</em> are in the same strongly connected 
+component if there are directed paths from <em>u</em> to <em>v</em> and 
+from <em>v</em> to <em>u</em>. The nodes are in the same weakly 
+connected component if, ignoring edge directions, there is a path 
+between them.
+<p>
 The type of components is specified by <b>method</b> parameter. 
-<em>v.net.components</em> creates a table and links it to the given <b>layer</b>.
-This table contains only two integer columns: <em>cat</em> and <em>comp
-</em>. If a point or both endpoints of a line belong to the same 
-component then the point/line is written to the output map and 
+<em>v.net.components</em> creates a table and links it to layer 1. This 
+table contains only two integer columns: <em>cat</em> and 
+<em>comp</em>. If a point or both endpoints of a line belong to the 
+same component then the point/line is written to the output map and 
 appropriate information is stored in the table. If <b>-a</b> flag is 
-set then new points are added on the nodes without points. These 
-points have category numbers larger than any category used in the 
-input map.
+set then new points are added on the nodes without points. These points 
+have category numbers larger than any category used in the input map.
+<p>
+One-way roads can be defined by assigning a cost of -1 to the 
+appropriate cost column (<b>arc_column</b> or 
+<b>arc_backward_column</b>. This affects only strongly connected 
+components. Network nodes can be closed by assigning a cost of -1 to 
+the node cost column. All nodes with a cost < 0 can not be traversed 
+and are end points, while all nodes with a cost ≥ 0 can be traversed. 
+This affects both weakly and strongly connected components.
 
 <h2>EXAMPLES</h2>
 
@@ -39,6 +45,7 @@
 <h2>AUTHORS</h2>
 
 Daniel Bundala, Google Summer of Code 2009, Student<br>
-Wolf Bergenheim, Mentor
+Wolf Bergenheim, Mentor<br>
+Markus Metz
 
 <p><i>Last changed: $Date$</i>



More information about the grass-commit mailing list