1v.net.distance(1) Grass User's Manual v.net.distance(1)
2
3
4
6 v.net.distance - Computes shortest distance via the network between
7 the given sets of features.
8 Finds the shortest paths from each ’from’ point to the nearest ’to’
9 feature and various information about this relation are uploaded to the
10 attribute table.
11
13 vector, network, shortest path
14
16 v.net.distance
17 v.net.distance --help
18 v.net.distance [-gl] input=name output=name [arc_layer=string]
19 [arc_type=string[,string,...]] [node_layer=string]
20 [from_layer=string] [from_cats=range] [from_where=sql_query]
21 [to_layer=string] [to_type=string[,string,...]] [to_cats=range]
22 [to_where=sql_query] [arc_column=name] [arc_backward_column=name]
23 [node_column=name] [--overwrite] [--help] [--verbose] [--quiet]
24 [--ui]
25
26 Flags:
27 -g
28 Use geodesic calculation for longitude-latitude locations
29
30 -l
31 Write each output path as one line, not as original input segments.
32
33 --overwrite
34 Allow output files to overwrite existing files
35
36 --help
37 Print usage summary
38
39 --verbose
40 Verbose module output
41
42 --quiet
43 Quiet module output
44
45 --ui
46 Force launching GUI dialog
47
48 Parameters:
49 input=name [required]
50 Name of input vector map
51 Or data source for direct OGR access
52
53 output=name [required]
54 Name for output vector map
55
56 arc_layer=string
57 Arc layer
58 Vector features can have category values in different layers. This
59 number determines which layer to use. When used with direct OGR
60 access this is the layer name.
61 Default: 1
62
63 arc_type=string[,string,...]
64 Arc type
65 Input feature type
66 Options: line, boundary
67 Default: line,boundary
68
69 node_layer=string
70 Node layer
71 Vector features can have category values in different layers. This
72 number determines which layer to use. When used with direct OGR
73 access this is the layer name.
74 Default: 2
75
76 from_layer=string
77 From layer number or name
78 Vector features can have category values in different layers. This
79 number determines which layer to use. When used with direct OGR
80 access this is the layer name.
81 Default: 1
82
83 from_cats=range
84 From category values
85 Example: 1,3,7-9,13
86
87 from_where=sql_query
88 From WHERE conditions of SQL statement without ’where’ keyword
89 Example: income < 1000 and population >= 10000
90
91 to_layer=string
92 Layer number or name
93 To layer number or name
94 Default: 1
95
96 to_type=string[,string,...]
97 To feature type
98 Options: point, line, boundary
99 Default: point
100
101 to_cats=range
102 To category values
103 Example: 1,3,7-9,13
104
105 to_where=sql_query
106 To WHERE conditions of SQL statement without ’where’ keyword
107 Example: income < 1000 and population >= 10000
108
109 arc_column=name
110 Arc forward/both direction(s) cost column (number)
111
112 arc_backward_column=name
113 Arc backward direction cost column (number)
114
115 node_column=name
116 Node cost column (number)
117
119 v.net.distance finds the nearest element in set to for every point in
120 set from.
121
123 These two sets are given by the respective layer, where and cats param‐
124 eters. The type of to features is specified by to_type parameter. All
125 from features are points. A table is linked to output map containing
126 various information about the relation. More specifically, the table
127 has three columns: cat, tcat and dist storing category of each from
128 feature, category of the nearest to feature and the distance between
129 them respectively.
130
131 Furthemore, the output map contains the shortest path between each cat,
132 tcat pair. Each path consists of several lines. If a line is on the
133 shortest path from a point then the category of this point is assigned
134 to the line. Note that every line may contain more than one category
135 value since a single line may be on the shortest path for more than one
136 from feature. And so the shortest paths can be easily obtained by
137 querying lines with corresponding category number. Alternatively,
138 unique paths can be created with the -l flag where each path will be a
139 separate single line in the output.
140
141 The costs of arcs in forward and backward direction are specified by
142 arc_column and arc_backward_column columns respectively. If arc_back‐
143 ward_column is not given, the same cost is used in both directions.
144
145 v.net.distance will not work if you are trying to find the nearest
146 neighbors within a group of nodes, i.e. where to and from are the same
147 set of nodes, as the closest node will be the node itself and the
148 result will be zero-length paths. In order to find nearest neighbors
149 within a group of nodes, you can either loop through each node as to
150 and all other nodes as from or create a complete distance matrix with
151 v.net.allpairs and select the lowest non-zero distance for each node.
152
154 Shortest path and distance between school and nearest hospital
155 Find shortest path and distance from every school to the nearest hospi‐
156 tal and show all paths.
157
158 Streets are grey lines, schools are green circles, hospitals are red
159 crosses, shortest paths are blue lines:
160
161 # connect schools to streets as layer 2
162 v.net input=streets_wake points=schools_wake output=streets_net1 \
163 operation=connect thresh=400 arc_layer=1 node_layer=2
164 # connect hospitals to streets as layer 3
165 v.net input=streets_net1 points=hospitals output=streets_net2 \
166 operation=connect thresh=400 arc_layer=1 node_layer=3
167 # inspect the result
168 v.category in=streets_net2 op=report
169 # shortest paths from schools (points in layer 2) to nearest hospitals (points in layer 3)
170 v.net.distance in=streets_net2 out=schools_to_hospitals flayer=2 to_layer=3
171 # visualization
172 g.region vector=streets_wake
173 d.mon wx0
174 d.vect streets_wake color=220:220:220
175 d.vect schools_wake color=green size=10
176 d.vect map=hospitals icon=basic/cross3 size=15 color=black fcolor=red
177 d.vect schools_to_hospitals
178
179 Distance between point source of pollution and sample points along streams
180 Example with streams of the NC sample data set.
181
182 # add coordinates of pollution point source of pollution as vector
183 pollution.txt:
184 634731.563206905|216390.501834892
185 v.in.ascii input=pollution.txt output=pollution
186 # add table to vector
187 v.db.addtable map=pollution
188 # add coordinates of sample points as vector
189 samples.txt:
190 634813.332814905|216333.590706166
191 634893.462007813|216273.763350851
192 634918.660011082|216254.949609689
193 v.in.ascii input=samples.txt output=samples
194 # add table to vector
195 v.db.addtable map=samples
196 # connect samples and pollution to streams
197 v.net -c input=streams points=samples output=streams_samples \
198 operation=connect node_layer=3 threshold=10 \
199 v.net -c input=streams_samples points=pollution
200 output=streams_samples_pollution operation=connect \
201 node_layer=4 threshold=10
202 # check vector layers
203 v.category input=streams_samples_pollution option=report
204 Layer/table: 1/streams_samples_pollution
205 type count min max
206 point 0 0 0
207 line 8562 40102 101351
208 boundary 0 0 0
209 centroid 0 0 0
210 area 0 0 0
211 face 0 0 0
212 kernel 0 0 0
213 all 8562 40102 101351
214 Layer: 3
215 type count min max
216 point 3 1 3
217 line 0 0 0
218 boundary 0 0 0
219 centroid 0 0 0
220 area 0 0 0
221 face 0 0 0
222 kernel 0 0 0
223 all 3 1 3
224 Layer: 4
225 type count min max
226 point 1 1 1
227 line 0 0 0
228 boundary 0 0 0
229 centroid 0 0 0
230 area 0 0 0
231 face 0 0 0
232 kernel 0 0 0
233 all 1 1 1
234 # calculate distance between sample points and pollution point source
235 v.net.distance input=streams_samples_pollution \
236 output=distance_samples_to_pollution from_layer=3 to_layer=4
237 # check results
238 v.report map=distance_samples_to_pollution@vnettest option=length
239 cat|tcat|dist|length
240 1|1|100.0|100.0
241 2|1|200.0|200.0
242 3|1|231.446|231.446
243
245 v.net.path, v.net.allpairs, v.net.distance, v.net.alloc
246
248 Daniel Bundala, Google Summer of Code 2009, Student
249 Wolf Bergenheim, Mentor
250 Markus Metz
251
253 Available at: v.net.distance source code (history)
254
255 Main index | Vector index | Topics index | Keywords index | Graphical
256 index | Full index
257
258 © 2003-2019 GRASS Development Team, GRASS GIS 7.8.2 Reference Manual
259
260
261
262GRASS 7.8.2 v.net.distance(1)