v.net.alloc.html 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <h2>DESCRIPTION</h2>
  2. <em>v.net.alloc</em> allocates subnets for nearest centers. Center
  3. nodes must be opened (costs &gt;= 0). Costs of center nodes are used in
  4. the calculation.
  5. <p>
  6. Costs may be either line lengths, or attributes saved in a
  7. database table. These attribute values are taken as costs of whole
  8. segments, not as costs to traverse a length unit (e.g. meter) of the
  9. segment. For example, if the speed limit is 100 km / h, the cost to
  10. traverse a 10 km long road segment must be calculated as
  11. <br>
  12. length / speed = 10 km / (100 km/h) = 0.1 h.
  13. <br>
  14. Supported are cost assignments for both arcs and nodes,
  15. and also different costs for both directions of a vector line.
  16. For areas, costs will be calculated along boundary lines.
  17. <p>
  18. The input vector needs to be prepared with <em>v.net operation=connect</em>
  19. in order to connect points representing center nodes to the network.
  20. <p>
  21. The nearest center can be determined using either costs from the
  22. nearest center or costs to the nearest center with option
  23. <b>method</b>. See example below.
  24. <p>
  25. By default, the category value of the nearest center is used as
  26. category value for output lines. With the <b>-u</b> flag, output lines
  27. become unique categories and an attribute table is created with the
  28. fields <em>cat, ocat, center</em>. The <em>ocat</em> field holds the
  29. original line category in <b>arc_layer</b> and the <em>center</em>
  30. field holds the center category in <b>node_layer</b>. Additionally,
  31. original line categories are copied from the input <b>arc_layer</b> to
  32. layer 2 in the output, together with any attribute table.
  33. <p>
  34. Application of flag <b>-t</b> enables a turntable support. This flag
  35. requires additional parameters <b>turn_layer</b> and
  36. <b>turn_cat_layer</b> that are otherwise ignored. The turntable allows
  37. to model e.g. traffic code, where some turns may be prohibited. This
  38. means that the input layer is expanded by turntable with costs of every
  39. possible turn on any possible node (intersection) in both directions.
  40. Turntable can be created by the <em><a href="v.net.html">v.net</a></em>
  41. module. For more information about turns in the vector network analyses
  42. see
  43. <a href="https://grasswiki.osgeo.org/wiki/Turns_in_the_vector_network_analysis">wiki page</a>.
  44. <h2>NOTES</h2>
  45. Nodes and arcs can be closed using cost = -1.
  46. <p>
  47. Center nodes can also be assigned to vector nodes using
  48. <em><a href="wxGUI.vdigit.html">wxGUI vector digitizer</a></em>.
  49. <h2>EXAMPLES</h2>
  50. <p>1. Subnetwork allocation using distance:
  51. <p><img src="v_net_alloc.png" alt="v.net.alloc example using distance" border="1">
  52. <br>
  53. <p>2. Subnetwork allocation using traveling time:
  54. <p><img src="v_net_alloc_time.png" alt="v.net.alloc example using time" border="1">
  55. <br>
  56. <p>Example 1: <em>Calculating subnets for 3 center nodes using distances</em>
  57. <div class="code"><pre>
  58. # Spearfish
  59. # center nodes:
  60. echo "591235.5|4926306.62|1
  61. 596591.8|4917042.5|2
  62. 602722.9|4923544.2|3" | v.in.ascii in=- out=centernodes
  63. g.copy vect=roads,myroads
  64. # connect points to network
  65. v.net myroads points=centernodes out=myroads_net op=connect thresh=200
  66. # allocate, specifying range of center cats (easier to catch all):
  67. v.net.alloc myroads_net out=myroads_net_alloc center_cats=1-100000 node_layer=2
  68. # report categories
  69. v.category myroads_net_alloc option=report
  70. </pre></div>
  71. To display the result, run for example:
  72. <div class="code"><pre>
  73. # show result
  74. g.region vector=myroads_net
  75. d.mon x0
  76. d.vect myroads_net layer=1
  77. # the result has to be selected by category number of the relevant node:
  78. d.vect myroads_net_alloc cat=1 col=red layer=1
  79. d.vect myroads_net_alloc cat=2 col=green layer=1
  80. d.vect myroads_net_alloc cat=3 col=yellow layer=1
  81. # center nodes
  82. d.vect myroads_net col=red icon=basic/triangle fcol=green size=12 layer=2
  83. </pre></div>
  84. <p>Example 2: <em>Calculating subnets for 3 center nodes using traveling time</em><br>
  85. <div class="code"><pre>
  86. # Spearfish
  87. # center nodes:
  88. echo "591235.5|4926306.62|1
  89. 596591.8|4917042.5|2
  90. 602722.9|4923544.2|3" | v.in.ascii in=- out=centernodes
  91. g.copy vect=roads,myroads
  92. # create lines map connecting points to network
  93. v.net myroads points=centernodes out=myroads_net op=connect thresh=500 arc_layer=1 node_layer=2
  94. # set up costs
  95. # create unique categories for each road in layer 3
  96. v.category in=myroads_net out=myroads_net_time opt=add cat=1 layer=3 type=line
  97. # add new table for layer 3
  98. 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"
  99. # copy road type to layer 3
  100. v.to.db myroads_net_time layer=3 qlayer=1 opt=query qcolumn=label columns=label
  101. # upload road length in miles
  102. v.to.db myroads_net_time layer=3 type=line option=length col=length unit=miles
  103. # set speed limits in miles / hour
  104. v.db.update myroads_net_time layer=3 col=speed val="5.0"
  105. v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='interstate'"
  106. v.db.update myroads_net_time layer=3 col=speed val="75.0" where="label='primary highway, hard surface'"
  107. v.db.update myroads_net_time layer=3 col=speed val="50.0" where="label='secondary highway, hard surface'"
  108. v.db.update myroads_net_time layer=3 col=speed val="25.0" where="label='light-duty road, improved surface'"
  109. v.db.update myroads_net_time layer=3 col=speed val="5.0" where="label='unimproved road'"
  110. # define traveling costs as traveling time in minutes:
  111. # set forward costs
  112. v.db.update myroads_net_time layer=3 col=cost val="length / speed * 60"
  113. # set backward costs
  114. v.db.update myroads_net_time layer=3 col=bcost val="length / speed * 60"
  115. # subnetwork allocation with fastest paths
  116. v.net.alloc in=myroads_net_time arc_layer=3 node_layer=2 arc_column=cost arc_backward_column=bcost out=myroads_net_alloc_time center_cats=1-3
  117. </pre></div>
  118. To display the result, run for example:
  119. <div class="code"><pre>
  120. # show result
  121. g.region vector=myroads_net
  122. d.mon x0
  123. d.vect myroads_net type=line layer=1
  124. # the result has to be selected by category number of the relevant node:
  125. d.vect myroads_net_alloc_time cat=1 col=red layer=1
  126. d.vect myroads_net_alloc_time cat=2 col=green layer=1
  127. d.vect myroads_net_alloc_time cat=3 col=yellow layer=1
  128. # center nodes
  129. d.vect myroads_net_time col=red icon=basic/triangle fcol=green size=12 type=point layer=2
  130. </pre></div>
  131. <p>Example 3: <em>Differences between costs from centers and costs to centers</em><br>
  132. Each lane of the two-lane road is a one-way road.
  133. <p>1. Subnetwork allocation from centers:
  134. <p><img src="v_net_alloc_from_centers.png" alt="v.net.alloc example from centers" border="1">
  135. <br>
  136. A center reaches any point following the one-way lanes.
  137. <p>2. Subnetwork allocation to centers:
  138. <p><img src="v_net_alloc_to_centers.png" alt="v.net.alloc example to centers" border="1">
  139. <br>
  140. Any node reaches reaches the nearest center following the one-way lanes.
  141. <p>
  142. In case of an accident, the ambulance should come from the nearest
  143. 'from' hospital and go to the nearest 'to' hospital.
  144. <div class="code"><pre>
  145. # North Carolina
  146. # center nodes are hospitals:
  147. # connect hospitals to streets as layer 2
  148. v.net input=streets_wake points=hospitals output=streets_hospitals operation=connect thresh=400 arc_layer=1 node_layer=2
  149. v.to.db map=streets_hospitals layer=1 type=line option=cat columns=cat
  150. # close oneway roads
  151. v.db.update map=streets_hospitals column=TF_COST value=-1 where="ONE_WAY = 'FT'"
  152. v.db.update map=streets_hospitals column=FT_COST value=-1 where="ONE_WAY = 'TF'"
  153. # add costs to newly created lines
  154. v.db.update map=streets_hospitals column=TF_COST value=0 where="cat > 49746"
  155. v.db.update map=streets_hospitals column=FT_COST value=0 where="cat > 49746"
  156. # from centers
  157. v.net.alloc in=streets_hospitals out=streets_hospitals_alloc_from center_cats=1-10000 arc_column=FT_COST arc_backward_column=TF_COST
  158. # to centers
  159. v.net.alloc in=streets_hospitals out=streets_hospitals_alloc_to method=to center_cats=1-10000 arc_column=FT_COST arc_backward_column=TF_COST
  160. </pre></div>
  161. <h2>SEE ALSO</h2>
  162. <em><a href="d.path.html">d.path</a></em>,
  163. <em><a href="v.net.html">v.net</a></em>,
  164. <em><a href="v.net.iso.html">v.net.iso</a></em>,
  165. <em><a href="v.net.path.html">v.net.path</a></em>,
  166. <em><a href="v.net.steiner.html">v.net.steiner</a></em>,
  167. <em><a href="v.net.salesman.html">v.net.salesman</a></em>
  168. <h2>AUTHOR</h2>
  169. Radim Blazek, ITC-Irst, Trento, Italy<br>
  170. Documentation: Markus Neteler, Markus Metz
  171. <h3>TURNS SUPPORT</h3>
  172. The turns support was implemnented as part of GRASS GIS turns cost project at Czech Technical University in Prague, Czech Republic.
  173. Eliska Kyzlikova, Stepan Turek, Lukas Bocan and Viera Bejdova participated at the project.
  174. Implementation: Stepan Turek
  175. Documentation: Lukas Bocan
  176. Mentor: Martin Landa
  177. <!--
  178. <p>
  179. <i>Last changed: $Date$</i>
  180. -->