v.select.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <h2>DESCRIPTION</h2>
  2. <em>v.select</em> allows the user to select features from a vector
  3. map by features from another one.
  4. <p>Supported operators (without GEOS; using GRASS' own algorithm):
  5. <ul>
  6. <li><b>overlap</b> - features partially or completely overlap (GEOS equivalent: intersects)
  7. </ul>
  8. Supported operators (internally using
  9. <a href="https://trac.osgeo.org/geos/">GEOS</a> - Geometry Engine, Open Source):
  10. <ul>
  11. <li><b>equals</b> - features are spatially equals</li>
  12. <li><b>disjoint</b> - features do not spatially intersect</li>
  13. <li><b>intersects</b> - features spatially intersect (equivalent to native 'overlap')</li>
  14. <li><b>touches</b> - features spatially touches</li>
  15. <li><b>crosses</b> - features spatially crosses</li>
  16. <li><b>within</b> - feature A is completely inside feature B</li>
  17. <li><b>contains</b> - feature B is completely inside feature A</li>
  18. <li><b>overlaps</b> - features spatially overlap</li>
  19. <li><b>relate</b> - feature A is spatially related to feature B</li>
  20. </ul>
  21. <h2>NOTES</h2>
  22. Only features with category numbers will be considered. If required
  23. the <em><a href="v.category.html">v.category</a></em> module can be
  24. used to add them. Typically boundaries do not need to be given a
  25. category number, as an area's attributes are inherited from the
  26. centroid. Typically points, lines, and centroids will always want to
  27. have a cat number. E.g. take a road which separates two farms. It is
  28. ambiguous as to which farm an attribute that is attached to the road
  29. belongs to. The boundary only needs a cat number if it will hold its
  30. own attributes, such as road name or pavement form. A centroid in each
  31. paddock holds the information with respect to ownership, area, etc.
  32. <h2>EXAMPLES</h2>
  33. Preparation of example data (North Carolina sample dataset):
  34. <div class="code"><pre>
  35. # Create an grid for overlaying to ZIP code vector map
  36. v.mkgrid map=boxgrid grid=10,10 position=coor \
  37. coordinates=583600,201500 box=5000,5000
  38. # set region to ZIP codes and boxgrid vector maps
  39. g.region vector=zipcodes_wake,boxgrid -p res=100 -a
  40. # enlarge region a bit for "white border" around map in monitor
  41. g.region n=n+1000 s=s-1000 w=w-1000 e=e+1000 -p
  42. d.mon wx0
  43. </pre></div>
  44. <h3>OVERLAP: features partially or completely overlap (using GRASS)</h3>
  45. Select grid boxes (North Carolina sample dataset):
  46. <div class="code"><pre>
  47. d.vect map=zipcodes_wake fill_color=0:128:0
  48. d.vect map=boxgrid fill_color=85:130:176
  49. v.select ainput=boxgrid binput=zipcodes_wake output=v_select_OVERLAP operator=overlap
  50. d.vect map=v_select_OVERLAP
  51. d.vect map=zipcodes_wake type=boundary color=50:50:50
  52. </pre></div>
  53. <center>
  54. <img src="v_select_op_overlap.png" alt="v.select with OVERLAP operator"><br>
  55. v.select with OVERLAP operator: selected grid boxes shown in grey
  56. </center>
  57. <h3>OVERLAPS features spatially overlap (using GEOS)</h3>
  58. Select grid boxes (North Carolina sample dataset):
  59. <div class="code"><pre>
  60. d.vect map=zipcodes_wake fill_color=0:128:0
  61. d.vect map=boxgrid fill_color=85:130:176
  62. v.select ainput=boxgrid binput=zipcodes_wake output=v_select_OVERLAPS operator=overlaps
  63. d.vect map=v_select_OVERLAPS
  64. d.vect map=zipcodes_wake type=boundary color=50:50:50
  65. </pre></div>
  66. <center>
  67. <img src="v_select_op_overlaps.png" alt="v.select with OVERLAPS operator"><br>
  68. v.select with OVERLAPS operator: selected grid boxes shown in grey
  69. </center>
  70. <h3>DISJOINT: features do not spatially intersect (using GEOS)</h3>
  71. Select grid boxes (North Carolina sample dataset):
  72. <div class="code"><pre>
  73. d.vect map=zipcodes_wake fill_color=0:128:0
  74. d.vect map=boxgrid fill_color=85:130:176
  75. v.select ainput=boxgrid binput=zipcodes_wake output=v_select_DISJOINT operator=disjoint
  76. d.vect map=v_select_DISJOINT
  77. d.vect map=zipcodes_wake type=boundary color=50:50:50
  78. </pre></div>
  79. <center>
  80. <img src="v_select_op_disjoint.png" alt="v.select with DISJOINT operator"><br>
  81. v.select with DISJOINT operator: selected grid boxes shown in grey
  82. </center>
  83. <h3>EQUALS: features are spatially equals (using GEOS)</h3>
  84. Select zipcode polygon (North Carolina sample dataset):
  85. <div class="code"><pre>
  86. d.vect map=zipcodes_wake fill_color=0:128:0
  87. v.extract input=zipcodes_wake where=ZIPCODE_ID=35 output=zipcodeID35
  88. v.select ainput=zipcodes_wake binput=zipcodeID35 output=v_select_EQUALS operator=equals
  89. d.vect map=v_select_EQUALS
  90. d.vect map=zipcodes_wake type=boundary color=50:50:50
  91. </pre></div>
  92. <center>
  93. <img src="v_select_op_equals.png" alt="v.select with EQUALS operator"><br>
  94. v.select with EQUALS operator: selected grid boxes shown in grey
  95. </center>
  96. <h3>INTERSECTS: features spatially intersect (using GEOS)</h3>
  97. Select zipcode polygons (North Carolina sample dataset):
  98. <div class="code"><pre>
  99. d.vect map=zipcodes_wake fill_color=0:128:0
  100. d.vect map=boxgrid fill_color=85:130:176
  101. v.select ainput=zipcodes_wake binput=boxgrid output=v_select_INTERSECTS operator=intersects
  102. d.vect map=v_select_INTERSECTS
  103. d.vect map=boxgrid type=boundary color=50:50:50
  104. </pre></div>
  105. <center>
  106. <img src="v_select_op_intersects.png" alt="v.select with INTERSECTS operator"><br>
  107. v.select with INTERSECTS operator: selected grid boxes shown in grey
  108. </center>
  109. <h3>TOUCHES: features spatially touches (using GEOS)</h3>
  110. Select polygons (North Carolina sample dataset):
  111. <div class="code"><pre>
  112. d.vect map=zipcodes_wake fill_color=0:128:0
  113. d.vect map=zipcodeID35 fill_color=85:130:176
  114. v.select ainput=zipcodes_wake binput=zipcodeID35 output=v_select_TOUCHES operator=touches
  115. d.vect map=v_select_TOUCHES
  116. d.vect map=zipcodes_wake type=boundary color=50:50:50
  117. </pre></div>
  118. <center>
  119. <img src="v_select_op_touches.png" alt="v.select with TOUCHES operator"><br>
  120. v.select with TOUCHES operator: selected polygons shown in grey (blue: input polygon)
  121. </center>
  122. <h3>CROSSES: features spatially crosses (using GEOS)</h3>
  123. Select zipcode polygons by lines (North Carolina sample dataset):
  124. <div class="code"><pre>
  125. d.vect map=zipcodes_wake fill_color=0:128:0
  126. d.vect map=busroute1 color=200:27:27 width=3
  127. v.select ainput=zipcodes_wake binput=busroute1 output=v_select_CROSSES operator=crosses
  128. d.vect map=v_select_CROSSES
  129. d.vect map=zipcodes_wake type=boundary color=50:50:50
  130. d.vect map=busroute1 color=200:27:27 width=3
  131. </pre></div>
  132. <center>
  133. <img src="v_select_op_crosses.png" alt="v.select with CROSSES operator"><br>
  134. v.select with CROSSES operator: selected polygons shown in grey (red: input lines)
  135. </center>
  136. <h3>WITHIN feature A is completely inside feature B (using GEOS)</h3>
  137. Select zipcode polygons (North Carolina sample dataset):
  138. <div class="code"><pre>
  139. d.vect map=zipcodes_wake fill_color=0:128:0
  140. d.vect map=boundary_county fill_color=85:130:176
  141. v.select ainput=zipcodes_wake binput=boundary_county output=v_select_WITHIN operator=within
  142. d.vect map=v_select_WITHIN
  143. </pre></div>
  144. <center>
  145. <img src="v_select_op_within.png" alt="v.select with WITHIN operator"><br>
  146. v.select with WITHIN operator: selected polygons shown in grey (blue: input polygons)
  147. </center>
  148. <h3>CONTAINS feature B is completely inside feature A (using GEOS)</h3>
  149. Select zipcode polygon (North Carolina sample dataset):
  150. <h4>CONTAINS with polygons</h4>
  151. <div class="code"><pre>
  152. d.vect map=zipcodes_wake fill_color=0:128:0
  153. d.vect map=zipcodeID35 fill_color=85:130:176
  154. v.select ainput=zipcodes_wake binput=zipcodeID35 \
  155. output=v_select_CONTAINS_pol operator=contains
  156. d.vect map=v_select_CONTAINS
  157. </pre></div>
  158. <center>
  159. <img src="v_select_op_contains_pol.png" alt="v.select with CONTAINS operator"><br>
  160. v.select with CONTAINS operator: selected polygon shown in grey (blue: input polygon, not visible)
  161. </center>
  162. <h4>CONTAINS with points</h4>
  163. <div class="code"><pre>
  164. d.vect map=zipcodes_wake fill_color=0:128:0
  165. d.vect map=hospitals fill_color=195:31:31 icon=basic/cross3 size=10
  166. v.select ainput=zipcodes_wake binput=hospitals \
  167. output=v_select_CONTAINS_pnts operator=contains
  168. d.vect map=v_select_CONTAINS_pnts
  169. d.vect map=hospitals fill_color=195:31:31 icon=basic/cross3 size=10
  170. </pre></div>
  171. <center>
  172. <img src="v_select_op_contains_pnts.png" alt="v.select with CONTAINS operator"><br>
  173. v.select with CONTAINS operator: selected polygons shown in grey (red: input points)
  174. </center>
  175. <h3>RELATE feature A is spatially related to feature B (using GEOS)</h3>
  176. This operator additionally requires the <b>relate</b> parameter (in other
  177. GIS called 'ST_Relate').
  178. This operator allows calculating the
  179. <a href="https://en.wikipedia.org/wiki/DE-9IM">Dimensionally Extended nine-Intersection Model (DE-9IM)</a>.
  180. In the following one example: Select polygon with 'TOUCHES' operator
  181. (North Carolina sample dataset):
  182. <div class="code"><pre>
  183. d.vect map=zipcodes_wake fill_color=0:128:0
  184. d.vect map=zipcodeID35 fill_color=85:130:176
  185. v.select ainput=zipcodeID35 binput=zipcodes_wake \
  186. output=v_select_TOUCHES_relate operator=relate relate='T********'
  187. d.vect map=v_select_TOUCHES
  188. </pre></div>
  189. The result of <tt>relate='T********'</tt> is the same as seen
  190. above in the example 'TOUCHES'.
  191. See the <a href="https://en.wikipedia.org/wiki/DE-9IM">DE-9IM</a> page
  192. for related operators and their definition.
  193. <h3>Extraction of points falling into a polygon</h3>
  194. Extract fire stations (points) falling into urban area (polygon) - North Carolina
  195. data set (point in polygon test):
  196. <div class="code"><pre>
  197. v.select ainput=firestations binput=urbanarea output=urban_firestations \
  198. operator=overlap
  199. </pre></div>
  200. <h3>Extraction of lines overlapping with a polygon</h3>
  201. Extract railroad lines from zip code map overlapping with the urban area
  202. (line in polygon test):
  203. <div class="code"><pre>
  204. v.select ainput=railroads binput=urbanarea \
  205. output=railroads_in_urbanarea operator=overlap
  206. </pre></div>
  207. <h3>Extraction of areas overlapping with a line</h3>
  208. Extract those areas from zip code map which overlap with railroads
  209. (polygon on line test):
  210. <div class="code"><pre>
  211. # first add a tiny buffer around railroad lines:
  212. v.buffer input=railroads output=railroads_buf20m \
  213. distance=20
  214. v.select ainput=zipcodes_wake binput=railroads_buf20m \
  215. output=zipcodes_wake_railroads operator=overlap
  216. </pre></div>
  217. <!-- 2015: still an issue?
  218. <h2>TODO</h2>
  219. Processing areas with GEOS is currently incredibly slow. Significant
  220. speed-up is desired.
  221. -->
  222. <h2>SEE ALSO</h2>
  223. <em>
  224. <a href="v.category.html">v.category</a>,
  225. <a href="v.clip.html">v.clip</a>,
  226. <a href="v.overlay.html">v.overlay</a>,
  227. <a href="v.extract.html">v.extract</a>
  228. </em>
  229. <p>
  230. <a href="sql.html">GRASS SQL interface</a><br>
  231. <a href="https://trac.osgeo.org/geos/">GEOS</a> - Geometry Engine, Open Source
  232. <h2>AUTHORS</h2>
  233. Radim Blazek<br>
  234. GEOS support by Martin Landa, Czech Technical University in Prague, Czech Republic<br>
  235. ZIP code examples by Carol X. Garzon-Lopez, Trento, Italy
  236. <p>
  237. <i>Last changed: $Date$</i>