.TH v.net.distance 1grass "" "GRASS 7.8.5" "GRASS GIS User's Manual" .SH NAME \fI\fBv.net.distance\fR\fR \- Computes shortest distance via the network between the given sets of features. .br Finds the shortest paths from each \(cqfrom\(cq point to the nearest \(cqto\(cq feature and various information about this relation are uploaded to the attribute table. .SH KEYWORDS vector, network, shortest path .SH SYNOPSIS \fBv.net.distance\fR .br \fBv.net.distance \-\-help\fR .br \fBv.net.distance\fR [\-\fBgl\fR] \fBinput\fR=\fIname\fR \fBoutput\fR=\fIname\fR [\fBarc_layer\fR=\fIstring\fR] [\fBarc_type\fR=\fIstring\fR[,\fIstring\fR,...]] [\fBnode_layer\fR=\fIstring\fR] [\fBfrom_layer\fR=\fIstring\fR] [\fBfrom_cats\fR=\fIrange\fR] [\fBfrom_where\fR=\fIsql_query\fR] [\fBto_layer\fR=\fIstring\fR] [\fBto_type\fR=\fIstring\fR[,\fIstring\fR,...]] [\fBto_cats\fR=\fIrange\fR] [\fBto_where\fR=\fIsql_query\fR] [\fBarc_column\fR=\fIname\fR] [\fBarc_backward_column\fR=\fIname\fR] [\fBnode_column\fR=\fIname\fR] [\-\-\fBoverwrite\fR] [\-\-\fBhelp\fR] [\-\-\fBverbose\fR] [\-\-\fBquiet\fR] [\-\-\fBui\fR] .SS Flags: .IP "\fB\-g\fR" 4m .br Use geodesic calculation for longitude\-latitude locations .IP "\fB\-l\fR" 4m .br Write each output path as one line, not as original input segments. .IP "\fB\-\-overwrite\fR" 4m .br Allow output files to overwrite existing files .IP "\fB\-\-help\fR" 4m .br Print usage summary .IP "\fB\-\-verbose\fR" 4m .br Verbose module output .IP "\fB\-\-quiet\fR" 4m .br Quiet module output .IP "\fB\-\-ui\fR" 4m .br Force launching GUI dialog .SS Parameters: .IP "\fBinput\fR=\fIname\fR \fB[required]\fR" 4m .br Name of input vector map .br Or data source for direct OGR access .IP "\fBoutput\fR=\fIname\fR \fB[required]\fR" 4m .br Name for output vector map .IP "\fBarc_layer\fR=\fIstring\fR" 4m .br Arc layer .br Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name. .br Default: \fI1\fR .IP "\fBarc_type\fR=\fIstring[,\fIstring\fR,...]\fR" 4m .br Arc type .br Input feature type .br Options: \fIline, boundary\fR .br Default: \fIline,boundary\fR .IP "\fBnode_layer\fR=\fIstring\fR" 4m .br Node layer .br Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name. .br Default: \fI2\fR .IP "\fBfrom_layer\fR=\fIstring\fR" 4m .br From layer number or name .br Vector features can have category values in different layers. This number determines which layer to use. When used with direct OGR access this is the layer name. .br Default: \fI1\fR .IP "\fBfrom_cats\fR=\fIrange\fR" 4m .br From category values .br Example: 1,3,7\-9,13 .IP "\fBfrom_where\fR=\fIsql_query\fR" 4m .br From WHERE conditions of SQL statement without \(cqwhere\(cq keyword .br Example: income < 1000 and population >= 10000 .IP "\fBto_layer\fR=\fIstring\fR" 4m .br Layer number or name .br To layer number or name .br Default: \fI1\fR .IP "\fBto_type\fR=\fIstring[,\fIstring\fR,...]\fR" 4m .br To feature type .br Options: \fIpoint, line, boundary\fR .br Default: \fIpoint\fR .IP "\fBto_cats\fR=\fIrange\fR" 4m .br To category values .br Example: 1,3,7\-9,13 .IP "\fBto_where\fR=\fIsql_query\fR" 4m .br To WHERE conditions of SQL statement without \(cqwhere\(cq keyword .br Example: income < 1000 and population >= 10000 .IP "\fBarc_column\fR=\fIname\fR" 4m .br Arc forward/both direction(s) cost column (number) .IP "\fBarc_backward_column\fR=\fIname\fR" 4m .br Arc backward direction cost column (number) .IP "\fBnode_column\fR=\fIname\fR" 4m .br Node cost column (number) .SH DESCRIPTION \fIv.net.distance\fR finds the nearest element in set \fIto\fR for every point in set \fIfrom\fR. .SH NOTES These two sets are given by the respective \fBlayer\fR, \fBwhere\fR and \fBcats\fR parameters. The type of \fIto\fR features is specified by \fBto_type\fR parameter. All \fIfrom\fR features are \fIpoints\fR. A table is linked to \fBoutput\fR map containing various information about the relation. More specifically, the table has three columns: \fIcat\fR, \fItcat\fR and \fIdist\fR storing category of each \fIfrom\fR feature, category of the nearest \fIto\fR feature and the distance between them respectively. .PP Furthemore, the \fBoutput\fR map contains the shortest path between each \fIcat\fR, \fItcat\fR 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 \fIfrom\fR 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 \fI\-l\fR flag where each path will be a separate single line in the output. .PP The costs of arcs in forward and backward direction are specified by \fBarc_column\fR and \fBarc_backward_column\fR columns respectively. If \fBarc_backward_column\fR is not given, the same cost is used in both directions. .PP \fIv.net.distance\fR will not work if you are trying to find the nearest neighbors within a group of nodes, i.e. where \fIto\fR and \fIfrom\fR are the same set of nodes, as the closest node will be the node itself and the result will be zero\-length paths. In order to find nearest neighbors within a group of nodes, you can either loop through each node as \fIto\fR and all other nodes as \fIfrom\fR or create a complete distance matrix with v.net.allpairs and select the lowest non\-zero distance for each node. .SH EXAMPLES .SS Shortest path and distance between school and nearest hospital Find shortest path and distance from every school to the nearest hospital and show all paths. .PP Streets are grey lines, schools are green circles, hospitals are red crosses, shortest paths are blue lines: .PP .PP .br .nf \fC # connect schools to streets as layer 2 v.net input=streets_wake points=schools_wake output=streets_net1 \(rs operation=connect thresh=400 arc_layer=1 node_layer=2 # connect hospitals to streets as layer 3 v.net input=streets_net1 points=hospitals output=streets_net2 \(rs operation=connect thresh=400 arc_layer=1 node_layer=3 # inspect the result v.category in=streets_net2 op=report # shortest paths from schools (points in layer 2) to nearest hospitals (points in layer 3) v.net.distance in=streets_net2 out=schools_to_hospitals flayer=2 to_layer=3 # visualization g.region vector=streets_wake d.mon wx0 d.vect streets_wake color=220:220:220 d.vect schools_wake color=green size=10 d.vect map=hospitals icon=basic/cross3 size=15 color=black fcolor=red d.vect schools_to_hospitals \fR .fi .SS Distance between point source of pollution and sample points along streams Example with streams of the NC sample data set. .PP .br .nf \fC # add coordinates of pollution point source of pollution as vector pollution.txt: 634731.563206905|216390.501834892 v.in.ascii input=pollution.txt output=pollution # add table to vector v.db.addtable map=pollution # add coordinates of sample points as vector samples.txt: 634813.332814905|216333.590706166 634893.462007813|216273.763350851 634918.660011082|216254.949609689 v.in.ascii input=samples.txt output=samples # add table to vector v.db.addtable map=samples # connect samples and pollution to streams v.net \-c input=streams points=samples output=streams_samples \(rs operation=connect node_layer=3 threshold=10 \(rs v.net \-c input=streams_samples points=pollution output=streams_samples_pollution operation=connect \(rs node_layer=4 threshold=10 # check vector layers v.category input=streams_samples_pollution option=report Layer/table: 1/streams_samples_pollution type count min max point 0 0 0 line 8562 40102 101351 boundary 0 0 0 centroid 0 0 0 area 0 0 0 face 0 0 0 kernel 0 0 0 all 8562 40102 101351 Layer: 3 type count min max point 3 1 3 line 0 0 0 boundary 0 0 0 centroid 0 0 0 area 0 0 0 face 0 0 0 kernel 0 0 0 all 3 1 3 Layer: 4 type count min max point 1 1 1 line 0 0 0 boundary 0 0 0 centroid 0 0 0 area 0 0 0 face 0 0 0 kernel 0 0 0 all 1 1 1 # calculate distance between sample points and pollution point source v.net.distance input=streams_samples_pollution \(rs output=distance_samples_to_pollution from_layer=3 to_layer=4 # check results v.report map=distance_samples_to_pollution@vnettest option=length cat|tcat|dist|length 1|1|100.0|100.0 2|1|200.0|200.0 3|1|231.446|231.446 \fR .fi .SH SEE ALSO \fI v.net.path, v.net.allpairs, v.net.distance, v.net.alloc \fR .SH AUTHORS Daniel Bundala, Google Summer of Code 2009, Student .br Wolf Bergenheim, Mentor .br Markus Metz .SH SOURCE CODE .PP Available at: v.net.distance source code (history) .PP Main index | Vector index | Topics index | Keywords index | Graphical index | Full index .PP © 2003\-2020 GRASS Development Team, GRASS GIS 7.8.5 Reference Manual