[GRASS-SVN] r46904 - in grass/trunk/vector: v.net.alloc v.net.allpairs v.net.centrality v.net.components v.net.distance v.net.iso v.net.path v.net.salesman v.net.steiner

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jul 1 04:55:08 EDT 2011


Author: mmetz
Date: 2011-07-01 01:55:08 -0700 (Fri, 01 Jul 2011)
New Revision: 46904

Modified:
   grass/trunk/vector/v.net.alloc/main.c
   grass/trunk/vector/v.net.allpairs/main.c
   grass/trunk/vector/v.net.centrality/main.c
   grass/trunk/vector/v.net.components/main.c
   grass/trunk/vector/v.net.distance/main.c
   grass/trunk/vector/v.net.iso/main.c
   grass/trunk/vector/v.net.path/path.c
   grass/trunk/vector/v.net.salesman/main.c
   grass/trunk/vector/v.net.steiner/main.c
Log:
remove bounding boxes from vector topology (Radim's TODO): update v.net.* modules

Modified: grass/trunk/vector/v.net.alloc/main.c
===================================================================
--- grass/trunk/vector/v.net.alloc/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.alloc/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -146,8 +146,46 @@
 			 abcol->answer, ncol->answer, geo, 0);
 
     nnodes = Vect_get_num_nodes(&Map);
+    nlines = Vect_get_num_lines(&Map);
 
     /* Create list of centers based on list of categories */
+    for (i = 1; i <= nlines; i++) {
+	int node;
+	
+	ltype = Vect_get_line_type(&Map, i);
+	if (!(ltype & GV_POINT))
+	    continue;
+
+	Vect_read_line(&Map, Points, Cats, i);
+	node = Vect_find_node(&Map, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	if (!node) {
+	    G_warning(_("Point is not connected to the network"));
+	    continue;
+	}
+	if (!(Vect_cat_get(Cats, nfield, &cat)))
+	    continue;
+	if (Vect_cat_in_cat_list(cat, catlist)) {
+	    Vect_net_get_node_cost(&Map, node, &n1cost);
+	    if (n1cost == -1) {	/* closed */
+		G_warning("Centre at closed node (costs = -1) ignored");
+	    }
+	    else {
+		if (acenters == ncenters) {
+		    acenters += 1;
+		    Centers =
+			(CENTER *) G_realloc(Centers,
+					     acenters * sizeof(CENTER));
+		}
+		Centers[ncenters].cat = cat;
+		Centers[ncenters].node = node;
+		G_debug(2, "centre = %d node = %d cat = %d", ncenters,
+			node, cat);
+		ncenters++;
+	    }
+	}
+    }
+
+#if 0
     for (node = 1; node <= nnodes; node++) {
 	nlines = Vect_get_node_n_lines(&Map, node);
 	for (j = 0; j < nlines; j++) {
@@ -178,6 +216,7 @@
 	    }
 	}
     }
+#endif
 
     G_message(_("Number of centers: [%d] (nlayer: [%d])"), ncenters, nfield);
 

Modified: grass/trunk/vector/v.net.allpairs/main.c
===================================================================
--- grass/trunk/vector/v.net.allpairs/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.allpairs/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -194,7 +194,8 @@
 	if (type == GV_POINT) {
 	    int node;
 
-	    Vect_get_line_nodes(&In, i, &node, NULL);
+	    /* Vect_get_line_nodes(&In, i, &node, NULL); */
+	    node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
 	    Vect_cat_get(Cats, layer, &cats[node]);
 	    if (cats[node] != -1) {
 		Vect_write_line(&Out, GV_POINT, Points, Cats);

Modified: grass/trunk/vector/v.net.centrality/main.c
===================================================================
--- grass/trunk/vector/v.net.centrality/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.centrality/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -322,7 +322,8 @@
 	    if (!Vect_cat_get(Cats, layer, &cat))
 		continue;
 	    Vect_write_line(&Out, type, Points, Cats);
-	    Vect_get_line_nodes(&In, i, &node, NULL);
+	    node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	    /* Vect_get_line_nodes(&In, i, &node, NULL); */
 	    process_node(node, cat);
 	    covered[node] = 1;
 	}

Modified: grass/trunk/vector/v.net.components/main.c
===================================================================
--- grass/trunk/vector/v.net.components/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.components/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -190,7 +190,8 @@
 	else if (type == GV_POINT) {
 	    int node;
 
-	    Vect_get_line_nodes(&In, i, &node, NULL);
+	    /* Vect_get_line_nodes(&In, i, &node, NULL); */
+	    node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
 	    comp = component[node];
 	    covered[node] = 1;
 	}

Modified: grass/trunk/vector/v.net.distance/main.c
===================================================================
--- grass/trunk/vector/v.net.distance/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.distance/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -64,7 +64,7 @@
 		      "the given sets of features.");
     module->description =
 	_("Finds the shortest paths from a feature 'to' to every feature 'from' "
-	 "and various information about this realtion are uploaded to the attribute table.");
+	 "and various information about this relation are uploaded to the attribute table.");
 
     /* Define the different options as defined in gis.h */
     map_in = G_define_standard_option(G_OPT_V_INPUT);
@@ -233,7 +233,15 @@
 
 	    if (!Vect_cat_get(Cats, flayer, &cat))
 		continue;
-	    Vect_get_line_nodes(&In, i, &node, NULL);
+		
+	    if (type & GV_POINTS) {
+		node = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	    }
+	    else {
+		Vect_get_line_nodes(&In, i, &node, NULL);
+	    }
+	    if (node < 1)
+		continue;
 	    Vect_write_line(&Out, type, Points, Cats);
 	    cost = dst[node] / (double)In.cost_multip;
 	    vertex = dglGetNode(graph, node);

Modified: grass/trunk/vector/v.net.iso/main.c
===================================================================
--- grass/trunk/vector/v.net.iso/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.iso/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -184,8 +184,44 @@
 			 abcol->answer, ncol->answer, geo, 0);
 
     nnodes = Vect_get_num_nodes(&Map);
+    nlines = Vect_get_num_lines(&Map);
 
     /* Create list of centres based on list of categories */
+    for (i = 1; i <= nlines; i++) {
+	ltype = Vect_get_line_type(&Map, i);
+	if (!(ltype & GV_POINT))
+	    continue;
+
+	Vect_read_line(&Map, Points, Cats, i);
+	node = Vect_find_node(&Map, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	if (!node) {
+	    G_warning(_("Point is not connected to the network"));
+	    continue;
+	}
+	if (!(Vect_cat_get(Cats, nfield, &cat)))
+	    continue;
+	if (Vect_cat_in_cat_list(cat, catlist)) {
+	    Vect_net_get_node_cost(&Map, node, &n1cost);
+	    if (n1cost == -1) {	/* closed */
+		G_warning(_("Centre at closed node (costs = -1) ignored"));
+	    }
+	    else {
+		if (acentres == ncentres) {
+		    acentres += 1;
+		    Centers =
+			(CENTER *) G_realloc(Centers,
+					     acentres * sizeof(CENTER));
+		}
+		Centers[ncentres].cat = cat;
+		Centers[ncentres].node = node;
+		G_debug(2, "centre = %d node = %d cat = %d", ncentres,
+			node, cat);
+		ncentres++;
+	    }
+	}
+    }
+
+#if 0
     for (node = 1; node <= nnodes; node++) {
 	nlines = Vect_get_node_n_lines(&Map, node);
 	for (j = 0; j < nlines; j++) {
@@ -216,6 +252,7 @@
 	    }
 	}
     }
+#endif
 
     G_message(_("Number of centres: %d (nlayer %d)"), ncentres, nfield);
 

Modified: grass/trunk/vector/v.net.path/path.c
===================================================================
--- grass/trunk/vector/v.net.path/path.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.path/path.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -118,7 +118,7 @@
 
     db_begin_transaction(driver);
 
-    /* Read stdin, find shortest path, and write connectin line and new database record */
+    /* Read stdin, find shortest path, and write connecting line and new database record */
     cat = 0;
     formaterr = nopoint = unreachable = 0;
     while (1) {
@@ -173,7 +173,9 @@
 	    }
 	    else {
 		fline = Citem->line;
-		Vect_get_line_nodes(In, fline, &fnode, NULL);
+		type = Vect_read_line(&In, Points, NULL, fline);
+		fnode = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+		/* Vect_get_line_nodes(In, fline, &fnode, NULL); */
 	    }
 	    G_debug(3, "from: cat = %5d point(line) = %5d node = %5d", fcat,
 		    fline, fnode);
@@ -191,7 +193,9 @@
 	    }
 	    else {
 		tline = Citem->line;
-		Vect_get_line_nodes(In, tline, &tnode, NULL);
+		type = Vect_read_line(&In, Points, NULL, tline);
+		tnode = Vect_find_node(&In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+		/* Vect_get_line_nodes(In, tline, &tnode, NULL); */
 	    }
 	    G_debug(3, "to  : cat = %5d point(line) = %5d node = %5d", tcat,
 		    tline, tnode);

Modified: grass/trunk/vector/v.net.salesman/main.c
===================================================================
--- grass/trunk/vector/v.net.salesman/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.salesman/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -95,6 +95,7 @@
     struct line_cats *Cats;
     struct line_pnts *Points;
     const char *dstr;
+    char buf[2000], buf2[2000];
 
     /* Initialize the GIS calls */
     G_gisinit(argv[0]);
@@ -192,8 +193,31 @@
     Vect_set_open_level(2);
     Vect_open_old(&Map, map->answer, "");
     nnodes = Vect_get_num_nodes(&Map);
+    nlines = Vect_get_num_lines(&Map);
 
     /* Create list of terminals based on list of categories */
+    for (i = 1; i <= nlines; i++) {
+	
+	ltype = Vect_get_line_type(&Map, i);
+	if (!(ltype & GV_POINT))
+	    continue;
+
+	Vect_read_line(&Map, Points, Cats, i);
+	node = Vect_find_node(&Map, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	if (!node) {
+	    G_warning(_("Point is not connected to the network"));
+	    continue;
+	}
+	if (!(Vect_cat_get(Cats, tfield, &cat)))
+	    continue;
+	if (Vect_cat_in_cat_list(cat, Clist)) {
+	    Vect_list_append(TList, node);
+	}
+	
+    }
+
+
+#if 0
     for (i = 1; i <= nnodes; i++) {
 	nlines = Vect_get_node_n_lines(&Map, i);
 	for (j = 0; j < nlines; j++) {
@@ -208,6 +232,8 @@
 	    }
 	}
     }
+#endif
+
     ncities = TList->n_values;
     G_message(_("Number of cities: [%d]"), ncities);
     if (ncities < 2)
@@ -419,41 +445,51 @@
     Vect_open_new(&Out, output->answer, Vect_is_3d(&Map));
     Vect_hist_command(&Out);
 
-    fprintf(stdout, "\nCycle:\n");
-    fprintf(stdout, "Arcs' categories (layer %d, %d arcs):\n", afield,
+    G_verbose_message(_("Cycle:"));
+    G_verbose_message(_("Arcs' categories (layer %d, %d arcs):"), afield,
 	    StArcs->n_values);
     for (i = 0; i < StArcs->n_values; i++) {
 	line = StArcs->value[i];
 	ltype = Vect_read_line(&Map, Points, Cats, line);
 	Vect_write_line(&Out, ltype, Points, Cats);
 	Vect_cat_get(Cats, afield, &cat);
-	if (i > 0)
-	    printf(",");
-	fprintf(stdout, "%d", cat);
+	if (i > 0) {
+	    sprintf(buf2, ", %d", cat);
+	    strcat(buf, buf2);
+	}
+	else
+	    sprintf(buf, "%d", cat);
     }
-    fprintf(stdout, "\n\n");
+    G_verbose_message("%s\n\n", buf);
 
-    fprintf(stdout, "Nodes' categories (layer %d, %d nodes):\n", tfield,
+    G_verbose_message(_("Nodes' categories (layer %d, %d nodes):"), tfield,
 	    StNodes->n_values);
     k = 0;
-    for (i = 0; i < StNodes->n_values; i++) {
-	node = StNodes->value[i];
-	nlines = Vect_get_node_n_lines(&Map, node);
-	for (j = 0; j < nlines; j++) {
-	    line = abs(Vect_get_node_line(&Map, node, j));
-	    ltype = Vect_read_line(&Map, Points, Cats, line);
-	    if (!(ltype & GV_POINT))
-		continue;
-	    if (!(Vect_cat_get(Cats, tfield, &cat)))
-		continue;
-	    Vect_write_line(&Out, ltype, Points, Cats);
-	    if (k > 0)
-		fprintf(stdout, ",");
-	    fprintf(stdout, "%d", cat);
-	    k++;
+    for (i = 0; i < TList->n_values; i++) {
+	double coor_x, coor_y, coor_z;
+	
+	node = TList->value[i];
+	Vect_get_node_coor(&Map, node, &coor_x, &coor_y, &coor_z);
+	line = Vect_find_line(&Map, coor_x, coor_y, coor_z, GV_POINT, 0, 0, 0);
+	
+	if (!line)
+	    continue;
+
+	ltype = Vect_read_line(&Map, Points, Cats, line);
+	if (!(ltype & GV_POINT))
+	    continue;
+	if (!(Vect_cat_get(Cats, tfield, &cat)))
+	    continue;
+	Vect_write_line(&Out, ltype, Points, Cats);
+	if (k > 0) {
+	    sprintf(buf2, ", %d", cat);
+	    strcat(buf, buf2);
 	}
+	else
+	    sprintf(buf, "%d", cat);
+	k++;
     }
-    fprintf(stdout, "\n\n");
+    G_verbose_message("%s\n\n", buf);
 
     Vect_build(&Out);
 

Modified: grass/trunk/vector/v.net.steiner/main.c
===================================================================
--- grass/trunk/vector/v.net.steiner/main.c	2011-07-01 08:54:19 UTC (rev 46903)
+++ grass/trunk/vector/v.net.steiner/main.c	2011-07-01 08:55:08 UTC (rev 46904)
@@ -332,6 +332,7 @@
     struct ilist *TList;	/* list of terminal nodes */
     struct ilist *StArcs;	/* list of arcs on Steiner tree */
     struct ilist *StNodes;	/* list of nodes on Steiner tree */
+    struct ilist *pointlist;
     double cost, tmpcost;
     struct cat_list *Clist;
     struct line_cats *Cats;
@@ -426,8 +427,28 @@
     Vect_set_open_level(2);
     Vect_open_old(&Map, map->answer, "");
     nnodes = Vect_get_num_nodes(&Map);
+    nlines = Vect_get_num_lines(&Map);
 
     /* Create list of terminals based on list of categories */
+    for (i = 1; i <= nlines; i++) {
+	ltype = Vect_get_line_type(&Map, i);
+	if (!(ltype & GV_POINT))
+	    continue;
+
+	Vect_read_line(&Map, Points, Cats, i);
+	node = Vect_find_node(&Map, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+	if (!node) {
+	    G_warning(_("Point is not connected to the network"));
+	    continue;
+	}
+	    if (!(Vect_cat_get(Cats, tfield, &cat)))
+		continue;
+	    if (Vect_cat_in_cat_list(cat, Clist)) {
+		Vect_list_append(TList, i);
+	    }
+    }
+
+#if 0
     for (i = 1; i <= nnodes; i++) {
 	nlines = Vect_get_node_n_lines(&Map, i);
 	for (j = 0; j < nlines; j++) {
@@ -442,6 +463,7 @@
 	    }
 	}
     }
+#endif
     nterms = TList->n_values;
     fprintf(stdout, "Number of terminals: %d\n", nterms);
 
@@ -611,11 +633,22 @@
 	    StNodes->n_values);
 
     k = 0;
+    pointlist = Vect_new_list();
     for (i = 0; i < StNodes->n_values; i++) {
+	double x, y, z;
+	struct bound_box box;
+	
 	node = StNodes->value[i];
+	
+	Vect_get_node_coor(&Map, node, &x, &y, &z);
+	box.E = box.W = x;
+	box.N = box.S = y;
+	box.T = box.B = z;
+	Vect_select_lines_by_box(&Map, &box, GV_POINT, pointlist);
+	
 	nlines = Vect_get_node_n_lines(&Map, node);
-	for (j = 0; j < nlines; j++) {
-	    line = abs(Vect_get_node_line(&Map, node, j));
+	for (j = 0; j < pointlist->n_values; j++) {
+	    line = pointlist->value[j];
 	    ltype = Vect_read_line(&Map, Points, Cats, line);
 	    if (!(ltype & GV_POINT))
 		continue;



More information about the grass-commit mailing list