Ver código fonte

v.net.distance: change path categories, adjust line directions

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@67990 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 9 anos atrás
pai
commit
3b124acd0a
2 arquivos alterados com 42 adições e 19 exclusões
  1. 31 8
      vector/v.net.distance/main.c
  2. 11 11
      vector/v.net.distance/v.net.distance.html

+ 31 - 8
vector/v.net.distance/main.c

@@ -50,6 +50,7 @@ int main(int argc, char *argv[])
     int from_nr;			/* 'from' features not reachable */
     dglInt32_t **nxt;
     struct line_cats **on_path;
+    char *segdir;
     char buf[2000];
 
     /* Attribute table */
@@ -221,11 +222,15 @@ int main(int argc, char *argv[])
     nodes_to_features = (int *)G_calloc(nnodes + 1, sizeof(int));
     on_path =
 	(struct line_cats **)G_calloc(nlines + 1, sizeof(struct line_cats *));
-    if (!dst || !nxt || !nodes_to_features || !on_path)
+    segdir = (char *)G_calloc(nlines + 1, sizeof(char));
+
+    if (!dst || !nxt || !nodes_to_features || !on_path || !segdir)
 	G_fatal_error(_("Out of memory"));
 
-    for (i = 1; i <= nlines; i++)
+    for (i = 1; i <= nlines; i++) {
 	on_path[i] = Vect_new_cats_struct();
+	segdir[i] = 0;
+    }
 
     /*initialise varrays and nodes list appropriatelly */
     afield = Vect_get_field_number(&In, afield_opt->answer);
@@ -299,6 +304,7 @@ int main(int argc, char *argv[])
     Vect_hist_copy(&In, &Out);
     Vect_hist_command(&Out);
 
+    G_message(_("Tracing paths from 'from' features ..."));
     from_nr = 0;
     for (i = 1; i <= nlines; i++) {
 	if (varrayf->c[i]) {
@@ -328,12 +334,18 @@ int main(int argc, char *argv[])
 	    vertex_id = node;
 	    slist->n_values = 0;
 	    while (nxt[vertex_id] != NULL) {
-		if (segments)
-		    Vect_cat_set(on_path
-				 [abs(dglEdgeGet_Id(graph, nxt[vertex_id]))], 1,
-				 cat);
+		int edge_id;
+
+		edge_id = (int) dglEdgeGet_Id(graph, nxt[vertex_id]);
+		if (segments) {
+		    Vect_cat_set(on_path[abs(edge_id)], 1, cat);
+		    if (edge_id < 0) {
+			segdir[abs(edge_id)] = 1;
+		    }
+		}
 		else
-		    G_ilist_add(slist, dglEdgeGet_Id(graph, nxt[vertex_id]));
+		    G_ilist_add(slist, edge_id);
+
 		vertex = dglEdgeGet_Tail(graph, nxt[vertex_id]);
 		vertex_id = dglNodeGet_Id(graph, vertex);
 	    }
@@ -365,6 +377,8 @@ int main(int argc, char *argv[])
 		    PPoints->n_points--;
 		}
 		PPoints->n_points++;
+		Vect_reset_cats(Cats);
+		Vect_cat_set(Cats, 1, cat);
 		Vect_write_line(&Out, GV_LINE, PPoints, Cats);
 	    }
 
@@ -374,7 +388,15 @@ int main(int argc, char *argv[])
     if (segments) {
 	for (i = 1; i <= nlines; i++) {
 	    if (on_path[i]->n_cats > 0) {
-		int type = Vect_read_line(&In, Points, NULL, i);
+		int type; 
+		
+		if (segdir[i]) {
+		    type = Vect_read_line(&In, PPoints, NULL, i);
+		    Vect_reset_line(Points);
+		    Vect_append_points(Points, PPoints, GV_BACKWARD);
+		}
+		else
+		    type = Vect_read_line(&In, Points, NULL, i);
 
 		Vect_write_line(&Out, type, Points, on_path[i]);
 	    }
@@ -395,6 +417,7 @@ int main(int argc, char *argv[])
     G_free(nodes_to_features);
     G_free(dst);
     G_free(nxt);
+    G_free(segdir);
 
     if (from_nr)
 	G_warning(n_("%d 'from' feature was not reachable",

+ 11 - 11
vector/v.net.distance/v.net.distance.html

@@ -15,20 +15,20 @@ and <em>dist</em> storing category of each <em>from</em>
 feature, category of the nearest <em>to</em> feature and the 
 distance between them respectively.
 <p>
-Furthemore, <b>output</b> map 
-contains the shorest path between each <em>cat</em>, <em>tcat</em> 
-pair. Each path consist of several lines. If a line is on the 
-shortest path from a point then the category of this point is 
-assigned to the line. Note that every line may contain more than one 
-category value since a single line may be on the shortest path for 
-more than one <em>from</em> feature. And so the shortest paths can 
-be easily obtained by querying lines with corresponding category 
+Furthemore, the <b>output</b> map contains the shortest path between 
+each <em>cat</em>, <em>tcat</em> pair. Each path consists of several 
+lines. If a line is on the shortest path from a point then the category 
+of this point is assigned to the line. Note that every line may contain 
+more than one category value since a single line may be on the shortest 
+path for more than one <em>from</em> feature. And so the shortest paths 
+can be easily obtained by querying lines with corresponding category 
 number. Alternatively, unique paths can be created with the <em>-l</em> 
 flag where each path will be a separate single line in the output.
-<br>
+<p>
 The costs of arcs in forward and backward direction are specified by 
-<b>arc_column</b> and <b>arc_backward_column</b> columns respectively. If
-<b>arc_backward_column</b> is not given, the same cost is used in both directions.  
+<b>arc_column</b> and <b>arc_backward_column</b> columns respectively. 
+If <b>arc_backward_column</b> is not given, the same cost is used in 
+both directions.  
 <p>
 <em>v.net.distance</em> will not work if you are trying to find the 
 nearest neighbors within a group of nodes, i.e. where <em>to</em>