[GRASS-SVN] r56600 - in grass-addons/grass7/vector: . v.net.path2
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jun 5 03:56:58 PDT 2013
Author: turek
Date: 2013-06-05 03:56:58 -0700 (Wed, 05 Jun 2013)
New Revision: 56600
Added:
grass-addons/grass7/vector/v.net.path2/
grass-addons/grass7/vector/v.net.path2/Makefile
grass-addons/grass7/vector/v.net.path2/main.c
grass-addons/grass7/vector/v.net.path2/path.c
grass-addons/grass7/vector/v.net.path2/v.net.path2.html
grass-addons/grass7/vector/v.net.path2/vnetpath.png
Log:
v.net.path2: dev version of v.net.path module with turns support
Added: grass-addons/grass7/vector/v.net.path2/Makefile
===================================================================
--- grass-addons/grass7/vector/v.net.path2/Makefile (rev 0)
+++ grass-addons/grass7/vector/v.net.path2/Makefile 2013-06-05 10:56:58 UTC (rev 56600)
@@ -0,0 +1,18 @@
+
+MODULE_TOPDIR = ../..
+
+PGM = v.net.path
+
+LIBES = $(VECTORLIB) $(DBMILIB) $(GISLIB)
+DEPENDENCIES = $(VECTORDEP) $(DBMIDEP) $(GISDEP)
+EXTRA_INC = $(VECT_INC)
+EXTRA_CFLAGS = $(VECT_CFLAGS)
+
+include $(MODULE_TOPDIR)/include/Make/Module.make
+
+
+default: cmd
+
+
+
+
Added: grass-addons/grass7/vector/v.net.path2/main.c
===================================================================
--- grass-addons/grass7/vector/v.net.path2/main.c (rev 0)
+++ grass-addons/grass7/vector/v.net.path2/main.c 2013-06-05 10:56:58 UTC (rev 56600)
@@ -0,0 +1,174 @@
+
+/****************************************************************
+ *
+ * MODULE: v.net.path2
+ *
+ * AUTHOR(S): Radim Blazek
+ *
+ * PURPOSE: Shortest path on vector network
+ *
+ * COPYRIGHT: (C) 2002, 2013 by the GRASS Development Team
+ *
+ * This program is free software under the
+ * GNU General Public License (>=v2).
+ * Read the file COPYING that comes with GRASS
+ * for details.
+ *
+ ****************************************************************/
+#include <stdlib.h>
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/glocale.h>
+
+int path(struct Map_info *, struct Map_info *, char *, int, double, int, int,
+ int, int);
+
+int main(int argc, char **argv)
+{
+ 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, *turntable_f;
+ struct GModule *module;
+ struct Map_info In, Out;
+ int type, afield, nfield, tfield, tucfield, geo;
+ double maxdist;
+
+ /* Initialize the GIS calls */
+ G_gisinit(argv[0]);
+
+ module = G_define_module();
+ G_add_keyword(_("vector"));
+ G_add_keyword(_("network"));
+ G_add_keyword(_("shortest path"));
+ module->description = _("Finds shortest path on vector network.");
+
+ input_opt = G_define_standard_option(G_OPT_V_INPUT);
+ output_opt = G_define_standard_option(G_OPT_V_OUTPUT);
+
+ type_opt = G_define_standard_option(G_OPT_V_TYPE);
+ type_opt->options = "line,boundary";
+ type_opt->answer = "line,boundary";
+ 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->label = _("Arc layer");
+
+ nfield_opt = G_define_standard_option(G_OPT_V_FIELD);
+ nfield_opt->key = "nlayer";
+ nfield_opt->answer = "2";
+ nfield_opt->label = _("Node layer");
+
+ tfield_opt = G_define_standard_option(G_OPT_V_FIELD);
+ tfield_opt->key = "tlayer";
+ tfield_opt->answer = "3";
+ tfield_opt->label = _("Turntable layer");
+
+ tucfield_opt = G_define_standard_option(G_OPT_V_FIELD);
+ tucfield_opt->key = "tuclayer";
+ tucfield_opt->answer = "4";
+ tucfield_opt->label = _("Unique categories layer for turntable");
+
+ file_opt = G_define_standard_option(G_OPT_F_INPUT);
+ file_opt->key = "file";
+ file_opt->required = NO;
+ 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");
+
+ abcol = G_define_option();
+ abcol->key = "abcolumn";
+ abcol->type = TYPE_STRING;
+ abcol->required = NO;
+ abcol->description = _("Arc backward direction cost column");
+
+ ncol = G_define_option();
+ ncol->key = "ncolumn";
+ ncol->type = TYPE_STRING;
+ ncol->required = NO;
+ ncol->description = _("Node cost column");
+
+ max_dist = G_define_option();
+ max_dist->key = "dmax";
+ max_dist->type = TYPE_DOUBLE;
+ max_dist->required = NO;
+ max_dist->answer = "1000";
+ max_dist->label = _("Maximum distance to the network");
+ max_dist->description = _("If start/end are given as coordinates. "
+ "If start/end point is outside this threshold, "
+ "the path is not found "
+ "and error message is printed. To speed up the process, keep this "
+ "value as low as possible.");
+
+ geo_f = G_define_flag();
+ geo_f->key = 'g';
+ geo_f->description =
+ _("Use geodesic calculation for longitude-latitude locations");
+
+ segments_f = G_define_flag();
+ segments_f->key = 's';
+ 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"
+ "(otherwise tuclayer and tlayer are ignored)");
+
+ 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);
+ tfield = atoi(tfield_opt->answer);
+ tucfield = atoi(tucfield_opt->answer);
+ maxdist = atof(max_dist->answer);
+
+ if (geo_f->answer) {
+ geo = 1;
+ if (G_projection() != PROJECTION_LL)
+ G_warning(_("The current projection is not longitude-latitude"));
+ }
+ else
+ geo = 0;
+
+ Vect_check_input_output_name(input_opt->answer, output_opt->answer,
+ G_FATAL_EXIT);
+
+ Vect_set_open_level(2);
+ Vect_open_old(&In, input_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>"),
+ output_opt->answer);
+ }
+ Vect_hist_command(&Out);
+
+ 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,
+ tfield, tucfield, turntable_f->answer);
+
+ Vect_close(&In);
+
+ Vect_build(&Out);
+ Vect_close(&Out);
+
+ exit(EXIT_SUCCESS);
+}
Added: grass-addons/grass7/vector/v.net.path2/path.c
===================================================================
--- grass-addons/grass7/vector/v.net.path2/path.c (rev 0)
+++ grass-addons/grass7/vector/v.net.path2/path.c 2013-06-05 10:56:58 UTC (rev 56600)
@@ -0,0 +1,373 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <math.h>
+#include <grass/gis.h>
+#include <grass/vector.h>
+#include <grass/dbmi.h>
+#include <grass/glocale.h>
+
+/* Result code */
+#define SP_OK 0 /* Path found */
+#define SP_UNREACHABLE 1 /* Node is not reachable */
+#define SP_NOPOINT 2 /* Missing point of given category */
+
+#define INPUT_MODE_NODE 1
+#define INPUT_MODE_COOR 2
+
+typedef struct
+{ /* category index */
+ int cat; /* line category */
+ int line; /* line number */
+} CIDX;
+
+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 tfield, int tucfield,
+ int use_ttb)
+{
+ FILE *in_file = NULL;
+ int i, nlines, line, npoints, type, cat, id, fcat, tcat, fline, tline,
+ fnode, tnode, count;
+ int ret, sp, input_mode, unreachable, nopoint, formaterr;
+ struct ilist *AList;
+ double cost;
+ struct line_pnts *Points, *OPoints, *FPoints, *TPoints;
+ struct line_cats *Cats;
+ CIDX *Cidx, *Citem;
+ char buf[2000], dummy[2000];
+ double fx, fy, tx, ty;
+
+ /* Attribute table */
+ dbString sql;
+ dbDriver *driver;
+ struct field_info *Fi;
+
+ if (filename) {
+ /* open input file */
+ if ((in_file = fopen(filename, "r")) == NULL)
+ G_fatal_error(_("Unable to open input file <%s>"), filename);
+ }
+
+ AList = Vect_new_list();
+ Points = Vect_new_line_struct();
+ OPoints = Vect_new_line_struct();
+ FPoints = Vect_new_line_struct();
+ TPoints = Vect_new_line_struct();
+ Cats = Vect_new_cats_struct();
+ db_init_string(&sql);
+
+ /* Create category index for input points */
+ npoints = Vect_get_num_primitives(In, GV_POINT);
+ Cidx = (CIDX *) G_malloc(npoints * sizeof(CIDX));
+
+ nlines = Vect_get_num_lines(In);
+ count = 0;
+ for (line = 1; line <= nlines; line++) {
+ type = Vect_read_line(In, NULL, Cats, line);
+ if (type != GV_POINT)
+ continue;
+
+ Vect_cat_get(Cats, nfield, &cat);
+
+ if (cat < 0)
+ continue;
+
+ Cidx[count].cat = cat;
+ Cidx[count].line = line;
+ count++;
+ }
+
+ if (count < npoints)
+ G_warning(_("[%d] points without category (nfield: [%d])"),
+ npoints - count, nfield);
+
+ npoints = count;
+
+ qsort((void *)Cidx, npoints, sizeof(CIDX), cmp);
+
+ /* Create table */
+ Fi = Vect_default_field_info(Out, 1, NULL, GV_1TABLE);
+ Vect_map_add_dblink(Out, 1, NULL, Fi->table, GV_KEY_COLUMN, Fi->database,
+ Fi->driver);
+
+ driver = db_start_driver_open_database(Fi->driver, Fi->database);
+ if (driver == NULL)
+ G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
+ Fi->database, Fi->driver);
+
+ sprintf(buf,
+ "create table %s ( cat integer, id integer, fcat integer, tcat integer, "
+ "sp integer, cost double precision, fdist double precision, tdist double precision )",
+ Fi->table);
+
+ db_set_string(&sql, buf);
+ G_debug(2, db_get_string(&sql));
+
+ if (db_execute_immediate(driver, &sql) != DB_OK) {
+ db_close_database_shutdown_driver(driver);
+ G_fatal_error(_("Unable to create table: '%s'"), db_get_string(&sql));
+ }
+
+ if (db_create_index2(driver, Fi->table, GV_KEY_COLUMN) != DB_OK)
+ G_warning(_("Cannot create index"));
+
+ if (db_grant_on_table
+ (driver, Fi->table, DB_PRIV_SELECT, DB_GROUP | DB_PUBLIC) != DB_OK)
+ G_fatal_error(_("Cannot grant privileges on table <%s>"), Fi->table);
+
+ db_begin_transaction(driver);
+
+ /* Read stdin, find shortest path, and write connecting line and new database record */
+ cat = 0;
+ formaterr = nopoint = unreachable = 0;
+ while (1) {
+
+ if (!filename) {
+ if (fgets(buf, sizeof(buf), stdin) == NULL)
+ break;
+ }
+ else {
+ if (G_getl2(buf, sizeof(buf) - 1, in_file) == 0)
+ break;
+ }
+
+
+ double fdist, tdist;
+
+ G_chop(buf);
+
+ ret =
+ sscanf(buf, "%d %lf %lf %lf %lf %s", &id, &fx, &fy, &tx, &ty,
+ dummy);
+ if (ret == 5) {
+ input_mode = INPUT_MODE_COOR;
+ }
+ else {
+ ret = sscanf(buf, "%d %d %d %s", &id, &fcat, &tcat, dummy);
+ if (ret != 3) {
+ G_warning(_("Wrong input format: %s"), buf);
+ formaterr++;
+ continue;
+ }
+ input_mode = INPUT_MODE_NODE;
+ }
+
+ G_debug(3, "mode = %d", input_mode);
+
+ cat++; /* Output category */
+ sp = SP_OK;
+ cost = fdist = tdist = 0;
+
+ if (input_mode == INPUT_MODE_NODE) {
+ /* From */
+ Citem =
+ (CIDX *) bsearch((void *)&fcat, Cidx, npoints, sizeof(CIDX),
+ cmp);
+ if (Citem == NULL) {
+ G_warning(_("No point with category [%d]"), fcat);
+ sp = SP_NOPOINT;
+ fline = 0;
+ fnode = 0;
+ nopoint++;
+ }
+ 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);
+ /* Vect_get_line_nodes(In, fline, &fnode, NULL); */
+ }
+ G_debug(3, "from: cat = %5d point(line) = %5d node = %5d", fcat,
+ fline, fnode);
+
+ /* To */
+ Citem =
+ (CIDX *) bsearch((void *)&tcat, Cidx, npoints, sizeof(CIDX),
+ cmp);
+ if (Citem == NULL) {
+ G_warning(_("No point with category [%d]"), tcat);
+ sp = SP_NOPOINT;
+ tline = 0;
+ tnode = 0;
+ nopoint++;
+ }
+ 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);
+ /* 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) {
+ if (use_ttb)
+ ret =
+ Vect_net_ttb_shortest_path(In, fnode, 0, tnode, 0,
+ tfield, tucfield, AList,
+ &cost);
+ else
+ ret =
+ Vect_net_shortest_path(In, fnode, tnode, AList,
+ &cost);
+
+ if (ret == -1) {
+ sp = SP_UNREACHABLE;
+ unreachable++;
+ G_warning(_("Point with category [%d] is not reachable "
+ "from point with category [%d]"), tcat, fcat);
+ }
+ else {
+ /* Write new line connecting 'from' and 'to' */
+ G_debug(3, "Number of arcs = %d, total costs = %f",
+ AList->n_values, cost);
+
+ Vect_reset_cats(Cats);
+ Vect_cat_set(Cats, 1, cat);
+
+ if (segments) {
+ for (i = 0; i < AList->n_values; i++) {
+ line = AList->value[i];
+ Vect_read_line(In, Points, NULL, abs(line));
+
+ if (line > 0) {
+ Vect_write_line(Out, GV_LINE, Points, Cats);
+ }
+ else {
+ Vect_reset_line(OPoints);
+ Vect_append_points(OPoints, Points,
+ GV_BACKWARD);
+ Vect_write_line(Out, GV_LINE, OPoints, Cats);
+ }
+ }
+ }
+ else {
+ Vect_reset_line(OPoints);
+
+ for (i = 0; i < AList->n_values; i++) {
+ line = AList->value[i];
+ Vect_read_line(In, Points, NULL, abs(line));
+ if (line > 0)
+ Vect_append_points(OPoints, Points,
+ GV_FORWARD);
+ else
+ Vect_append_points(OPoints, Points,
+ GV_BACKWARD);
+ }
+
+ Vect_write_line(Out, GV_LINE, OPoints, Cats);
+ }
+ }
+ }
+ }
+ else { /* INPUT_MODE_COOR */
+ fcat = tcat = 0;
+
+ if (use_ttb)
+ ret =
+ Vect_net_ttb_shortest_path_coor(In, fx, fy, 0.0, tx, ty,
+ 0.0, maxdist, maxdist,
+ tfield, tucfield, &cost,
+ OPoints, AList, 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, FPoints,
+ TPoints, &fdist, &tdist);
+
+ if (ret == 0) {
+ sp = SP_UNREACHABLE;
+ unreachable++;
+ G_warning(_("Point %f,%f is not reachable from "
+ "point %f,%f"), tx, ty, fx, fy);
+ }
+ else {
+ Vect_reset_cats(Cats);
+ Vect_cat_set(Cats, 1, cat);
+
+ if (segments) {
+ /* From point to the first node */
+ if (FPoints->n_points > 0)
+ Vect_write_line(Out, GV_LINE, FPoints, Cats);
+
+ /* On the network */
+ for (i = 0; i < AList->n_values; i++) {
+ line = AList->value[i];
+
+ Vect_read_line(In, Points, NULL, abs(line));
+
+ if (line > 0) {
+ Vect_write_line(Out, GV_LINE, Points, Cats);
+ }
+ else {
+ Vect_reset_line(OPoints);
+ Vect_append_points(OPoints, Points, GV_BACKWARD);
+ Vect_write_line(Out, GV_LINE, OPoints, Cats);
+ }
+ }
+
+ /* From last node to point */
+ if (TPoints->n_points > 0)
+ Vect_write_line(Out, GV_LINE, TPoints, Cats);
+
+ }
+ else {
+ Vect_write_line(Out, GV_LINE, OPoints, Cats);
+ }
+ }
+ }
+
+ sprintf(buf,
+ "insert into %s values ( %d, %d, %d, %d, %d, %f, %f, %f)",
+ Fi->table, cat, id, fcat, tcat, sp, cost, fdist, tdist);
+ db_set_string(&sql, buf);
+ G_debug(3, db_get_string(&sql));
+
+ if (db_execute_immediate(driver, &sql) != DB_OK) {
+ db_close_database_shutdown_driver(driver);
+ G_fatal_error(_("Cannot insert new record: %s"),
+ db_get_string(&sql));
+ }
+ }
+
+ db_commit_transaction(driver);
+
+ db_close_database_shutdown_driver(driver);
+
+ Vect_destroy_list(AList);
+ Vect_destroy_line_struct(Points);
+ Vect_destroy_line_struct(OPoints);
+ Vect_destroy_cats_struct(Cats);
+
+ if (filename)
+ fclose(in_file);
+
+ if (formaterr)
+ G_warning(_("[%d] input format errors"), formaterr);
+ if (nopoint)
+ G_warning(_("[%d] points of given category missing"), nopoint);
+ if (unreachable)
+ G_warning(_("%d destination(s) unreachable (including points out "
+ "of threshold)"), unreachable);
+
+ return 1;
+}
+
+int cmp(const void *pa, const void *pb)
+{
+ CIDX *p1 = (CIDX *) pa;
+ CIDX *p2 = (CIDX *) pb;
+
+ if (p1->cat < p2->cat)
+ return -1;
+ if (p1->cat > p2->cat)
+ return 1;
+ return 0;
+}
Added: grass-addons/grass7/vector/v.net.path2/v.net.path2.html
===================================================================
--- grass-addons/grass7/vector/v.net.path2/v.net.path2.html (rev 0)
+++ grass-addons/grass7/vector/v.net.path2/v.net.path2.html 2013-06-05 10:56:58 UTC (rev 56600)
@@ -0,0 +1,175 @@
+<h2>DESCRIPTION</h2>
+
+<em>v.net.path</em> determines least costly, e.g. shortest or fastest
+path(s) on a vector network.
+
+<p>
+Costs may be either line lengths, or attributes saved in a database
+table. These attribute values are taken as costs of whole segments, not
+as costs to traverse a length unit (e.g. meter) of the segment.
+For example, if the speed limit is 100 km / h, the cost to traverse a
+10 km long road segment must be calculated as
+<br>
+length / speed = 10 km / (100 km/h) = 0.1 h.
+<br>
+Supported are cost assignments for both arcs and nodes,
+and also different costs for both directions of a vector line.
+For areas, costs will be calculated along boundary lines.
+<p>
+The input vector needs to be prepared with <em>v.net operation=connect</em>
+in order to connect points representing center nodes to the network.
+
+<p>Nodes and arcs can be closed using cost = -1.
+<p>Least cost paths are written to the output vector map with an
+attached attribute table.
+<p>Nodes can be
+<ul>
+<li> piped into the program from file or from stdin, or
+<li> defined in the graphical user interface ("enter values interactively").
+</ul>
+
+The syntax is as follows:
+<div class="code"><pre>
+id start_point_category end_point_category
+</pre></div>
+
+(Example: 1 1 2)
+<p>
+or
+
+<div class="code"><pre>
+id start_point_x start_point_y end_point_x end_point_y
+</pre></div>
+
+<p>
+Points specified by category must be exactly on network nodes, and the
+input vector map needs to be prepared with <em>v.net operation=connect</em>.
+<p>
+When specifying coordinates, the next network node to a given coordinate
+pair is used.
+
+<p>
+The attribute table will contain the following attributes:
+
+<ul>
+ <li>cat - path unique category assigned by module</li>
+ <li>id - path id (read from input)</li>
+ <li>fcat - from point category</li>
+ <li>tcat - to point category</li>
+ <li>sp - result status:
+ <ul>
+ <li> 0 - OK, path found</li>
+ <li> 1 - node is not reachable</li>
+ <li> 2 - point of given category does not exist</li>
+ </ul>
+ <li>cost - travelling costs (on the network, not to/from network)</li>
+ <li>fdist - the distance from first point to the network</li>
+ <li>tdist - the distance from the network to second point</li>
+</ul>
+<p>There is the option of applying the <a href="v.net.turntable.html">v.net.turntable</a> module on the input layer first. This means the input layer is expanded by turntable with costs of every possible turn on any possible node (intersection) in both directions. Note that after this expansion it is required to apply the -t flag. This flag enables additional parameters tlayer and tuclayer that are otherwise ignored.
+
+<h2>NOTES</h2>
+Nodes and arcs can be closed using cost = -1.
+<p>If the cost columns 'afcol', 'abcol' and 'ncol' are not
+specified, the length of network segments is measured and
+zero costs are assumed for nodes.
+<p>When using attributes, the length of segments is not used. To get
+accurate results, the line length must be taken into account when
+assigning costs as attributes. For example, to get the <b>fastest path</b>,
+the columns 'max_speed' and 'length' are required. The correct fastest
+path can then be found by specifying <tt>afcol=length/max_speed</tt>. If not yet
+existing, the column containing the line length ("length") has to added to the
+attributes table using <em>v.to.db</em>.
+
+<h2>EXAMPLE</h2>
+
+Shortest (red) and fastest (blue) path between two digitized nodes (Spearfish):
+
+<p><img src="vnetpath.png" alt="v.net.path example" border="1">
+
+<p><div class="code"><pre>
+# Spearfish
+
+echo "1|601955.1|4916944.9|start
+2|594385.6|4921565.2|end" | v.in.ascii in=- cat=1 x=2 y=3 out=startend col="cat integer, \
+ east double precision, north double precision, label varchar(6)"
+
+v.db.select startend
+
+g.copy vect=roads,myroads
+
+# create lines map connecting points to network
+v.net myroads points=startend out=myroads_net op=connect thresh=500 alayer=1 nlayer=2
+
+# set up costs
+
+# create unique categories for each road in layer 3
+v.category in=myroads_net out=myroads_net_time opt=add cat=1 layer=3 type=line
+
+# add new table for layer 3
+v.db.addtable myroads_net_time layer=3 col="cat integer,label varchar(43),length double precision,speed double precision,cost double precision,bcost double precision"
+
+# copy road type to layer 3
+v.to.db myroads_net_time layer=3 qlayer=1 opt=query qcolumn=label columns=label
+
+# upload road length in miles
+v.to.db myroads_net_time layer=3 type=line option=length col=length unit=miles
+
+# set speed limits in miles / hour
+v.db.update myroads_net_time layer=3 col=speed val="5.0"
+v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='interstate'"
+v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='primary highway, hard surface'"
+v.db.update myroads_net_time layer=3 col=speed val="50.0" where="label='secondary highway, hard surface'"
+v.db.update myroads_net_time layer=3 col=speed val="25.0" where="label='light-duty road, improved surface'"
+v.db.update myroads_net_time layer=3 col=speed val="5.0" where="label='unimproved road'"
+
+# define traveling costs as traveling time in minutes:
+
+# set forward costs
+v.db.update myroads_net_time layer=3 col=cost val="length / speed * 60"
+# set backward costs
+v.db.update myroads_net_time layer=3 col=bcost val="length / speed * 60"
+
+# ... the 'start' and 'end' nodes have category number 1 and 2
+
+# Shortest path: ID as first number, then cat1 and cat2
+echo "1 1 2" | v.net.path myroads_net_time alayer=3 nlayer=2 out=mypath
+
+# Fastest path: ID as first number, then cat1 and cat2
+echo "1 1 2" | v.net.path myroads_net_time alayer=3 nlayer=2 afcol=cost abcol=bcost out=mypath_time
+</pre></div>
+
+To display the result, run for example:
+
+<div class="code"><pre>
+g.region vect=myroads_net
+d.mon x0
+d.vect myroads_net
+# show shortest path
+d.vect mypath col=red width=2
+# show fastest path
+d.vect mypath_time col=blue width=2
+
+# start and end point
+d.vect myroads_net icon=basic/triangle fcol=green size=12 layer=2
+d.font font=Vera
+d.vect startend disp=cat type=point lsize=14 layer=2
+</pre></div>
+
+
+<h2>SEE ALSO</h2>
+
+<em><a href="d.path.html">d.path</a></em>,
+<em><a href="v.net.html">v.net</a></em>,
+<em><a href="v.net.alloc.html">v.net.alloc</a></em>,
+<em><a href="v.net.iso.html">v.net.iso</a></em>,
+<em><a href="v.net.salesman.html">v.net.salesman</a></em>,
+<em><a href="v.net.steiner.html">v.net.steiner</a></em>,
+<em><a href="v.to.db.html">v.to.db</a></em>
+
+<h2>AUTHOR</h2>
+
+Radim Blazek, ITC-Irst, Trento, Italy<br>
+Documentation: Markus Neteler, Markus Metz
+
+<p><i>Last changed: $Date: 2013-05-23 21:59:24 +0200 (Thu, 23 May 2013) $</i>
Added: grass-addons/grass7/vector/v.net.path2/vnetpath.png
===================================================================
(Binary files differ)
Property changes on: grass-addons/grass7/vector/v.net.path2/vnetpath.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the grass-commit
mailing list