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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Jun 29 06:53:33 PDT 2014


Author: turek
Date: 2014-06-29 06:53:33 -0700 (Sun, 29 Jun 2014)
New Revision: 61061

Modified:
   grass/trunk/vector/v.net.path/main.c
   grass/trunk/vector/v.net.path/path.c
   grass/trunk/vector/v.net.path/v.net.path.html
Log:
v.net.path: added support for the turntable, guisections reorganized

Modified: grass/trunk/vector/v.net.path/main.c
===================================================================
--- grass/trunk/vector/v.net.path/main.c	2014-06-29 11:54:33 UTC (rev 61060)
+++ grass/trunk/vector/v.net.path/main.c	2014-06-29 13:53:33 UTC (rev 61061)
@@ -4,10 +4,11 @@
  * MODULE:       v.net.path
  * 
  * AUTHOR(S):    Radim Blazek
- *               
+ *               Stepan Turek <stepan.turek seznam.cz> (turns support)               
+ *
  * PURPOSE:      Shortest path on vector network
  *               
- * COPYRIGHT:    (C) 2002 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002, 2014 by the GRASS Development Team
  *
  *               This program is free software under the 
  *               GNU General Public License (>=v2). 
@@ -20,17 +21,18 @@
 #include <grass/vector.h>
 #include <grass/glocale.h>
 
-int path(struct Map_info *, struct Map_info *, char *, int, double, int);
+int path(struct Map_info *, struct Map_info *, char *, int, double, int,
+	 int, int);
 
 int main(int argc, char **argv)
 {
-    struct Option *input_opt, *output_opt, *afield_opt, *nfield_opt, *afcol,
-	*abcol, *ncol, *type_opt;
+    struct Option *input_opt, *output_opt, *afield_opt, *nfield_opt,
+	*tfield_opt, *tucfield_opt, *afcol, *abcol, *ncol, *type_opt;
     struct Option *max_dist, *file_opt;
-    struct Flag *geo_f, *segments_f;
+    struct Flag *geo_f, *segments_f, *turntable_f;
     struct GModule *module;
     struct Map_info In, Out;
-    int type, afield, nfield, geo;
+    int type, afield, nfield, tfield, tucfield, geo;
     double maxdist;
 
     /* Initialize the GIS calls */
@@ -48,16 +50,19 @@
     type_opt = G_define_standard_option(G_OPT_V_TYPE);
     type_opt->options = "line,boundary";
     type_opt->answer = "line,boundary";
+    type_opt->required = YES;
     type_opt->label = _("Arc type");
 
     afield_opt = G_define_standard_option(G_OPT_V_FIELD);
     afield_opt->key = "alayer";
     afield_opt->answer = "1";
+    afield_opt->required = YES;
     afield_opt->label = _("Arc layer");
 
     nfield_opt = G_define_standard_option(G_OPT_V_FIELD);
     nfield_opt->key = "nlayer";
     nfield_opt->answer = "2";
+    nfield_opt->required = YES;
     nfield_opt->label = _("Node layer");
 
     file_opt = G_define_standard_option(G_OPT_F_INPUT);
@@ -66,24 +71,26 @@
     file_opt->description = _("Name of file containing start and end points. "
 			      "If not given, read from stdin");
 
-
     afcol = G_define_option();
     afcol->key = "afcolumn";
     afcol->type = TYPE_STRING;
     afcol->required = NO;
     afcol->description = _("Arc forward/both direction(s) cost column");
+    afcol->guisection = _("Costs");
 
     abcol = G_define_option();
     abcol->key = "abcolumn";
     abcol->type = TYPE_STRING;
     abcol->required = NO;
     abcol->description = _("Arc backward direction cost column");
+    abcol->guisection = _("Costs");
 
     ncol = G_define_option();
     ncol->key = "ncolumn";
     ncol->type = TYPE_STRING;
     ncol->required = NO;
     ncol->description = _("Node cost column");
+    ncol->guisection = _("Costs");
 
     max_dist = G_define_option();
     max_dist->key = "dmax";
@@ -97,6 +104,22 @@
 			      "and error message is printed. To speed up the process, keep this "
 			      "value as low as possible.");
 
+    tfield_opt = G_define_standard_option(G_OPT_V_FIELD);
+    tfield_opt->key = "tlayer";
+    tfield_opt->answer = "3";
+    tfield_opt->label = _("Turntable layer");
+    tfield_opt->description =
+	_("If the -t flag is given, the parameter is required");
+    tfield_opt->guisection = _("Turntable");
+
+    tucfield_opt = G_define_standard_option(G_OPT_V_FIELD);
+    tucfield_opt->key = "tuclayer";
+    tucfield_opt->answer = "4";
+    tucfield_opt->label = _("Layer with unique categories used in turntable");
+    tucfield_opt->description =
+	_("If the -t flag is given, the parameter is required");
+    tucfield_opt->guisection = _("Turntable");
+
     geo_f = G_define_flag();
     geo_f->key = 'g';
     geo_f->description =
@@ -107,12 +130,16 @@
     segments_f->description = _("Write output as original input segments, "
 				"not each path as one line.");
 
+    turntable_f = G_define_flag();
+    turntable_f->key = 't';
+    turntable_f->description = _("Use turntable"
+				 "(tuclayer and tlayer are required with this flag).");
+
+
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     type = Vect_option_to_types(type_opt);
-    afield = atoi(afield_opt->answer);
-    nfield = atoi(nfield_opt->answer);
     maxdist = atof(max_dist->answer);
 
     if (geo_f->answer) {
@@ -130,6 +157,11 @@
     if (Vect_open_old(&In, input_opt->answer, "") < 0)
 	G_fatal_error(_("Unable to open vector map <%s>"), input_opt->answer);
 
+    afield = Vect_get_field_number(&In, afield_opt->answer);
+    nfield = Vect_get_field_number(&In, nfield_opt->answer);
+    tfield = Vect_get_field_number(&In, tfield_opt->answer);
+    tucfield = Vect_get_field_number(&In, tucfield_opt->answer);
+
     if (1 > Vect_open_new(&Out, output_opt->answer, Vect_is_3d(&In))) {
 	Vect_close(&In);
 	G_fatal_error(_("Unable to create vector map <%s>"),
@@ -137,10 +169,16 @@
     }
     Vect_hist_command(&Out);
 
-    Vect_net_build_graph(&In, type, afield, nfield, afcol->answer,
-			 abcol->answer, ncol->answer, geo, 0);
+    if (turntable_f->answer)
+	Vect_net_ttb_build_graph(&In, type, afield, nfield, tfield, tucfield,
+				 afcol->answer, abcol->answer, ncol->answer,
+				 geo, 0);
+    else
+	Vect_net_build_graph(&In, type, afield, nfield, afcol->answer,
+			     abcol->answer, ncol->answer, geo, 0);
 
-    path(&In, &Out, file_opt->answer, nfield, maxdist, segments_f->answer);
+    path(&In, &Out, file_opt->answer, nfield, maxdist, segments_f->answer,
+	 tucfield, turntable_f->answer);
 
     Vect_close(&In);
 

Modified: grass/trunk/vector/v.net.path/path.c
===================================================================
--- grass/trunk/vector/v.net.path/path.c	2014-06-29 11:54:33 UTC (rev 61060)
+++ grass/trunk/vector/v.net.path/path.c	2014-06-29 13:53:33 UTC (rev 61061)
@@ -24,7 +24,7 @@
 int cmp(const void *, const void *);
 
 int path(struct Map_info *In, struct Map_info *Out, char *filename,
-	 int nfield, double maxdist, int segments)
+	 int nfield, double maxdist, int segments, int tucfield, int use_ttb)
 {
     FILE *in_file = NULL;
     int i, nlines, line, npoints, type, cat, id, fcat, tcat, fline, tline,
@@ -174,7 +174,9 @@
 	    else {
 		fline = Citem->line;
 		type = Vect_read_line(In, Points, NULL, fline);
-		fnode = Vect_find_node(In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+		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,
@@ -194,14 +196,23 @@
 	    else {
 		tline = Citem->line;
 		type = Vect_read_line(In, Points, NULL, tline);
-		tnode = Vect_find_node(In, Points->x[0], Points->y[0], Points->z[0], 0, 0);
+		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);
 
 	    if (sp != SP_NOPOINT) {
-		ret = Vect_net_shortest_path(In, fnode, tnode, AList, &cost);
+		if (use_ttb)
+		    ret =
+			Vect_net_ttb_shortest_path(In, fnode, 0, tnode, 0,
+						   tucfield, AList, &cost);
+		else
+		    ret =
+			Vect_net_shortest_path(In, fnode, tnode, AList,
+					       &cost);
 
 		if (ret == -1) {
 		    sp = SP_UNREACHABLE;
@@ -254,12 +265,22 @@
 	}
 	else {			/* INPUT_MODE_COOR */
 	    fcat = tcat = 0;
-	    ret =
-		Vect_net_shortest_path_coor(In, fx, fy, 0.0, tx, ty, 0.0,
-					    maxdist, maxdist, &cost, OPoints,
-					    AList, NULL, FPoints, TPoints, &fdist,
-					    &tdist);
 
+	    if (use_ttb)
+		ret =
+		    Vect_net_ttb_shortest_path_coor(In, fx, fy, 0.0, tx, ty,
+						    0.0, maxdist, maxdist,
+						    tucfield, &cost,
+						    OPoints, AList, NULL,
+						    FPoints, TPoints, &fdist,
+						    &tdist);
+	    else
+		ret =
+		    Vect_net_shortest_path_coor(In, fx, fy, 0.0, tx, ty, 0.0,
+						maxdist, maxdist, &cost,
+						OPoints, AList, NULL, FPoints,
+						TPoints, &fdist, &tdist);
+
 	    if (ret == 0) {
 		sp = SP_UNREACHABLE;
 		unreachable++;

Modified: grass/trunk/vector/v.net.path/v.net.path.html
===================================================================
--- grass/trunk/vector/v.net.path/v.net.path.html	2014-06-29 11:54:33 UTC (rev 61060)
+++ grass/trunk/vector/v.net.path/v.net.path.html	2014-06-29 13:53:33 UTC (rev 61061)
@@ -67,6 +67,22 @@
     <li>tdist - the distance from the network to second point</li>
 </ul>
 
+<p>
+
+Application of flag <b>-t</b> enables a turntable support. 
+This flag requires additional parameters <b>tlayer</b> and <b>tuclayer</b> 
+that are otherwise ignored.
+ The turntable allows 
+to model e.g. trafic code, where some turns may be prohibited. 
+This means that the input layer is expanded by 
+turntable with costs of every possible turn on any possible node 
+(intersection) in both directions. 
+ Turntable can be created by 
+ the <em><a href="v.net.html">v.net</a></em> module. 
+For more information about turns in the vector network analyses see
+<a href="http://grasswiki.osgeo.org/wiki/Turns_in_the_vector_network_analysis">wiki page</a>.
+
+
 <h2>NOTES</h2>
 Nodes and arcs can be closed using cost = -1. 
 <p>If the cost columns 'afcol', 'abcol' and 'ncol' are not
@@ -171,4 +187,13 @@
 Radim Blazek, ITC-Irst, Trento, Italy<br>
 Documentation: Markus Neteler, Markus Metz
 
+<h3>TURNS SUPPORT</h3>
+
+The turns support was implemnented as part of GRASS GIS turns cost project at Czech Technical University in Prague, Czech Republic.  
+Eliska Kyzlikova, Stepan Turek, Lukas Bocan and Viera Bejdova participated at the project.
+
+Implementation: Stepan Turek 
+Documentation: Lukas Bocan
+Mentor: Martin Landa
+
 <p><i>Last changed: $Date$</i>



More information about the grass-commit mailing list