v.net.path(1grass)
π v.net.path π
so bestie, you clicked into v.net.path(1grass) from the GRASS User's Manual and honestly? iconic choice. this is the one that finds the shortest path on a vector network. let's go π¦
β¨ NAME β¨
v.net.path β finds shortest path on vector network. that's the whole vibe. π
π·οΈ KEYWORDS π·οΈ
vector, network, shortest path
π SYNOPSIS π
v.net.path
v.net.path --help
v.net.path [-tgs] input=name output=name arc_layer=string
arc_type=string[,string,...] node_layer=string [file=name]
[arc_column=string] [arc_backward_column=string]
[node_column=string] [dmax=float] [turn_layer=string]
[turn_cat_layer=string] [--overwrite] [--help] [--verbose]
[--quiet] [--ui]
π© Flags π©
-tβ use turntable-gβ use geodesic calculation for longitude-latitude projects-sβ write output as original input segments, not each path as one line. (no more merge-into-one-line energy π )--overwriteβ let output files overwrite existing files--helpβ print usage summary--verboseβ verbose module output--quietβ quiet module output--uiβ force launching GUI dialog
ποΈ Parameters ποΈ
input=name[required] β name of input vector map. or, like, a data source for direct OGR access.output=name[required] β name for output vector maparc_layer=string[required] β arc layer. vector features can have category values in different layers, and this number decides which layer we're using, periodt. when used with direct OGR access this is the layer name. Default:1arc_type=string[,string,...][required] β arc type, aka input feature type. Options:line,boundary. Default:line,boundarynode_layer=string[required] β node layer. same layer-lore as above: this number determines which layer to use, and with direct OGR access it's the layer name. Default:2file=nameβ name of file containing start and end points. if you don't give it one, it reads from stdin π»arc_column=stringβ arc forward/both direction(s) cost column (number)arc_backward_column=stringβ arc backward direction cost column (number)node_column=stringβ node cost column (number)dmax=floatβ maximum distance to the network. this kicks in when start/end are given as coordinates. if a start/end point is outside this threshold, the path is not found and an error message is printed. and to speed up the process, keep this value as low as possible. Default:1000turn_layer=stringβ layer with turntable. relevant only with the-tflag. Default:3turn_cat_layer=stringβ layer with unique categories used in turntable. relevant only with the-tflag. Default:4
πΈ DESCRIPTION πΈ
v.net.path determines the least costly path(s) on a vector network β so like, shortest or fastest, whichever cost function you're feeling. π
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
length / speed = 10 km / (100 km/h) = 0.1 h.
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. πΊοΈ
The input vector needs to be prepared with v.net operation=connect in order to connect points representing center nodes to the network.
Nodes and arcs can be closed using cost = -1. (yes, negative one, we love a sentinel value π)
Least cost paths are written to the output vector map with an attached attribute table.
Nodes can be:
- piped into the program from file or from stdin, or
- defined in the graphical user interface ("enter values interactively").
The syntax is as follows:
id start_point_category end_point_category
(Example: 1 1 2)
or
id start_point_x start_point_y end_point_x end_point_y
Points specified by category must be exactly on network nodes, and the input vector map needs to be prepared with v.net operation=connect.
When specifying coordinates, the next network node to a given coordinate pair is used.
The attribute table will contain the following attributes:
catβ path unique category assigned by moduleidβ path id (read from input)fcatβ from point categorytcatβ to point categoryspβ result status:0β OK, path found1β node is not reachable2β point of given category does not exist
costβ travelling costs (on the network, not to/from network)fdistβ the distance from first point to the networktdistβ the distance from the network to second point
Application of flag -t enables a turntable support. This flag requires additional parameters turn_layer and turn_cat_layer that are otherwise ignored. The turntable allows to model e.g. traffic 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 v.net module. For more information about turns in the vector network analyses see wiki page. π¦
π NOTES π
Nodes and arcs can be closed using cost = -1.
If the cost columns arc_column, arc_backward_column and node_column are not specified, the length of network segments is measured and zero costs are assumed for nodes.
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 fastest path, the columns βmax_speedβ and βlengthβ are required. The correct fastest path can then be found by specifying arc_column=length/max_speed. If not yet existing, the column containing the line length ("length") has to added to the attributes table using v.to.db. β οΈ
bestie pay attention here β if you skip the length, your "fastest" path is NOT it. the math is the math.
π§ͺ EXAMPLE π§ͺ
Shortest (red) and fastest (blue) path between two digitized nodes (Spearfish):
# 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 arc_layer=1 node_layer=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 arc_layer=3 node_layer=2 out=mypath
# Fastest path: ID as first number, then cat1 and cat2
echo "1 1 2" | v.net.path myroads_net_time arc_layer=3 node_layer=2 arc_column=cost arc_backward_column=bcost out=mypath_time
To display the result, run for example:
g.region vector=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
π SEE ALSO π
d.path, v.net, v.net.alloc, v.net.iso, v.net.salesman, v.net.steiner, v.to.db
π AUTHORS π
- Radim Blazek, ITC-Irst, Trento, Italy
- Documentation: Markus Neteler, Markus Metz
π¦ TURNS SUPPORT π¦
The turns support was implemnented as part of GRASS GIS turns cost project at Czech Technical University in Prague, Czech Republic.
- Implementation: Stepan Turek
- Documentation: Lukas Bocan, Eliska Kyzlikova, Viera Bejdova
- Mentor: Martin Landa
πΎ SOURCE CODE πΎ
Available at: v.net.path source code (history)
Latest change: Friday May 09 14:33:40 2025 in commit: b356c7e108fcbeca77474c8e83ebec8f1e7b3e4a
Main index | Vector index | Topics index | Keywords index | Graphical index | Full index
okay that's the whole thing bestie, go find your shortest path, you got this πβ¨π¦
this was GRASS 8.5.0 β Β© 2003-2026 GRASS Development Team, from the GRASS 8.5.0 Reference Manual, last touched in that May 09 2025 commit we just mentioned. mwah, bye ππ
π¦ where this page comes from
- alpine 3.24: grass-gis-doc 8.5.0-r1 Β· GPL-2.0-or-later
- ubuntu stonking: grass-doc 8.5.0-1ubuntu1 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms