[GRASS-SVN] r67990 - grass/trunk/vector/v.net.distance
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Mar 3 12:44:45 PST 2016
Author: mmetz
Date: 2016-03-03 12:44:45 -0800 (Thu, 03 Mar 2016)
New Revision: 67990
Modified:
grass/trunk/vector/v.net.distance/main.c
grass/trunk/vector/v.net.distance/v.net.distance.html
Log:
v.net.distance: change path categories, adjust line directions
Modified: grass/trunk/vector/v.net.distance/main.c
===================================================================
--- grass/trunk/vector/v.net.distance/main.c 2016-03-03 09:38:07 UTC (rev 67989)
+++ grass/trunk/vector/v.net.distance/main.c 2016-03-03 20:44:45 UTC (rev 67990)
@@ -50,6 +50,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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",
Modified: grass/trunk/vector/v.net.distance/v.net.distance.html
===================================================================
--- grass/trunk/vector/v.net.distance/v.net.distance.html 2016-03-03 09:38:07 UTC (rev 67989)
+++ grass/trunk/vector/v.net.distance/v.net.distance.html 2016-03-03 20:44:45 UTC (rev 67990)
@@ -15,20 +15,20 @@
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>
More information about the grass-commit
mailing list