vectorlib_topology.dox 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. /*! \page vlibTopology Topology
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \par Table of contents
  4. - \ref vlibTopoManagement
  5. - \ref vlibTopoFileFormat
  6. - \ref vlibTopoFileHead
  7. - \ref vlibTopoFileBody
  8. - \ref vlibTopoLevels
  9. - \ref vlibTopoExamples
  10. - \ref vlibTopoMemory
  11. \section vlibTopoManagement Vector library topology management
  12. Topology general characteristics:
  13. - geometry and attributes are stored separately
  14. (don't read both if it is not necessary - usually it is not)
  15. - the format is topological (areas build from boundaries)
  16. - currently only 2D topology is supported
  17. Topology is written for native GRASS vector format; in case of
  18. linked OGR sources (see <tt>v.external</tt> module), only
  19. pseudo-topology (boundaries constructed from polygons) is written.
  20. The following rules apply to the vector data:
  21. - Boundaries should not cross each other (i.e., boundaries which would
  22. cross must be split at their intersection to form distict boundaries).
  23. On the contrary, lines can cross each other, e.g. bridges over rivers.
  24. - Lines and boundaries share nodes only if their endpoints are identical.
  25. Lines or boundaries can be forced to share a common node by snapping
  26. them together. This is particulary important since nodes
  27. are not represented in the coor file, but only implicitly as
  28. endpoints of lines and boundaries.
  29. - Common area boundaries should appear only once (i.e., should not be
  30. double digitized).
  31. - Areas must be explicitly closed. This means that it must be possible
  32. to complete each area by following one or more boundaries that are
  33. connected by common nodes, and that such tracings result in closed
  34. areas.
  35. - It is recommended that area features and linear features be placed
  36. in separate layers. However if area features and linear features
  37. must appear in one layer, common boundaries should be digitized only
  38. once. For example, a boundary that is also a line (e.g., a road which
  39. is also a field boundary), should be digitized as a boundary to
  40. complete the area(s), and a boundary which is functionally also a line
  41. should be labeled as a line by a distinct category number.
  42. Vector map topology can be cleaned at user level by <tt>v.clean</tt>
  43. command.
  44. \subsection vlibTopoFileFormat Topo file format specification
  45. Topo file is read by Vect_open_topo().
  46. \subsubsection vlibTopoFileHead Header
  47. <i>Note:</i> <tt>plus</tt> is an instance of \ref Plus_head data structure.
  48. <table border="1" style="border-collapse: collapse" cellpadding="5">
  49. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  50. <tr><td>plus->Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  51. <tr><td>plus->Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  52. <tr><td>plus->Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  53. <tr><td>plus->Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  54. <tr><td>plus->port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  55. flag; files are written in machine native order but
  56. files in both little and big endian order may be
  57. readl; zero for little endian</td></tr>
  58. <tr><td>plus->head_size</td><td>L</td><td>1</td><td>header size</td></tr>
  59. <tr><td>plus->with_z</td><td>C</td><td>1</td><td>2D or 3D flag; zero for 2D</td></tr>
  60. <tr><td>plus->box</td><td>D</td><td>6</td><td>Bounding box coordinates (N,S,E,W,T,B)</td></tr>
  61. <tr><td>plus->n_nodes, plus->n_lines, etc.</td><td>I</td><td>7</td><td>Number of
  62. nodes, edges, lines, areas, isles, volumes and holes</td></tr>
  63. <tr><td>plus->n_plines, plus->n_llines, etc.</td><td>I</td><td>7</td><td>Number of
  64. points, lines, boundaries, centroids, faces and kernels</td></tr>
  65. <tr><td>plus->Node_offset, plus->Edge_offset,
  66. etc.</td><td>L</td><td>7</td><td>Offset value for nodes, edges, lines,
  67. areas, isles, volumes and holes</td></tr>
  68. <tr><td>plus->coor_size</td><td>L</td><td>1</td><td>File size</td></tr>
  69. </table>
  70. \subsubsection vlibTopoFileBody Body (nodes, lines, areas, isles)
  71. <b>Nodes</b>
  72. For each node (plus->n_nodes):
  73. <table border="1" style="border-collapse: collapse" cellpadding="5">
  74. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  75. <tr><td>n_lines</td><td>I</td><td>1</td><td>Number of lines (0 for dead node)</td></tr>
  76. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids (negative id for line which ends at the node)</td></tr>
  77. <tr><td>angles</td><td>D</td><td>n_lines</td><td>Angle value</td></tr>
  78. <tr><td>n_edges</td><td>I</td><td>1</td><td>Reserved for edges (only for <tt>with_z</tt>)</td></tr>
  79. <tr><td>x,y</td><td>D</td><td>2</td><td>Coordinate pair (2D)</td></tr>
  80. <tr><td>z</td><td>D</td><td>1</td><td>Only for <tt>with_z</tt> (3D)</td></tr>
  81. </table>
  82. See \ref P_node data structure.
  83. <b>Lines</b>
  84. For each line (plus->n_lines):
  85. <table border="1" style="border-collapse: collapse" cellpadding="5">
  86. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  87. <tr><td>feature type</td><td>C</td><td>1</td><td>0 for dead line</td></tr>
  88. <tr><td>offset</td><td>L</td><td>1</td><td>Line offset</td></tr>
  89. <tr><td>N1</td><td>I</td><td>1</td><td>Start node id (only if feature type is GV_LINE or GV_BOUNDARY)</td></tr>
  90. <tr><td>N2</td><td>I</td><td>1</td><td>End node id (only if feature type is GV_LINE or GV_BOUNDARY)</td></tr>
  91. <tr><td>left</td><td>I</td><td>1</td><td>Left area id for feature type GV_BOUNDARY / Area id for feature type GV_CENTROID</td></tr>
  92. <tr><td>right</td><td>I</td><td>1</td><td>Right area id (for feature type GV_BOUNDARY)</td></tr>
  93. <tr><td>vol</td><td>I</td><td>1</td><td>Reserved for kernel (volume number, for feature type GV_KERNEL)</td></tr>
  94. </table>
  95. See \ref P_line data structure.
  96. <b>Areas</b>
  97. For each area (plus->n_areas):
  98. <table border="1" style="border-collapse: collapse" cellpadding="5">
  99. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  100. <tr><td>n_lines</td><td>I</td><td>1</td><td>number of boundaries</td></tr>
  101. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids forming exterior boundary (clockwise order, negative id for backward direction)</td></tr>
  102. <tr><td>n_isles</td><td>I</td><td>1</td><td>Number of isles</td></tr>
  103. <tr><td>isles</td><td>I</td><td>n_isles</td><td>Isle ids</td></tr>
  104. <tr><td>centroid</td><td>I</td><td>1</td><td>Centroid id</td></tr>
  105. </table>
  106. See \ref P_area data structure.
  107. <b>Isles</b>
  108. For each isle (plus->n_isle):
  109. <table border="1" style="border-collapse: collapse" cellpadding="5">
  110. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  111. <tr><td>n_lines</td><td>I</td><td>1</td><td>number of boundaries</td></tr>
  112. <tr><td>lines</td><td>I</td><td>n_lines</td><td>Line ids forming exterior boundary (counter-clockwise order, negative id for backward direction)</td></tr>
  113. <tr><td>area</td><td>I</td><td>1</td><td>Outer area id</td></tr>
  114. </table>
  115. See \ref P_isle data structure.
  116. \subsection vlibTopoLevels Topology levels
  117. The vector library defines more <i>topology levels</i> (only for level
  118. of access 2):
  119. - GV_BUILD_NONE
  120. - GV_BUILD_BASE
  121. - GV_BUILD_AREAS
  122. - GV_BUILD_ATTACH_ISLES
  123. - GV_BUILD_CENTROIDS
  124. - GV_BUILD_ALL
  125. <i>Note:</i> Only the geometry type GV_BOUNDARY is used to build
  126. areas. The geometry type GV_LINE cannot form an area.
  127. \subsection vlibTopoExamples Topology examples
  128. <b>Points</b>
  129. \verbatim
  130. One point (nodes: 0, lines: 1, areas: 0, isles: 0)
  131. + N1/L1
  132. \endverbatim
  133. Line L1 (see \ref P_line)
  134. \verbatim
  135. line = 1, type = 1 (GV_POINT)
  136. \endverbatim
  137. <b>Lines</b>
  138. \verbatim
  139. One line (nodes: 2, lines: 1, areas: 0, isles: 0)
  140. +----L1----+
  141. N1 N2
  142. \endverbatim
  143. %Node N1 (see \ref P_node)
  144. \verbatim
  145. node = 1, n_lines = 1, xyz = 634624.746450, 223557.302231, 0.000000
  146. line = 1, type = 2 (GV_LINE), angle = -0.436257
  147. \endverbatim
  148. %Node N2 (see \ref P_node)
  149. \verbatim
  150. node = 2, n_lines = 1, xyz = 638677.484787, 221667.849899, 0.000000
  151. line = -1, type = 2 (GV_LINE), angle = 2.705335
  152. \endverbatim
  153. Line L1 (see \ref P_line)
  154. \verbatim
  155. line = 1, type = 2 (GV_LINE), n1 = 1, n2 = 2
  156. \endverbatim
  157. <b>Areas without holes</b>
  158. \verbatim
  159. Two lines (nodes: 1, lines: 2, areas: 1, isles: 1)
  160. +N1
  161. / \
  162. / \
  163. / \
  164. / +L2 \
  165. / \
  166. -------L1------
  167. \endverbatim
  168. %Node N1 (see \ref P_node)
  169. \verbatim
  170. node = 1, n_lines = 2, xyz = 635720.081136, 225063.387424, 0.000000
  171. line = 1, type = 4 (GV_BOUNDARY), angle = -2.245537
  172. line = -1, type = 4 (GV_BOUNDARY), angle = -0.842926
  173. \endverbatim
  174. Line L1 (see \ref P_line)
  175. \verbatim
  176. line = 1, type = 4 (GV_BOUNDARY), n1 = 1, n2 = 1, left = 1, right = -1
  177. \endverbatim
  178. Line L2 (see \ref P_line)
  179. \verbatim
  180. line = 2, type = 8 (GV_CENTROID), area = 1
  181. \endverbatim
  182. Area A1 (see \ref P_area)
  183. \verbatim
  184. area = 1, n_lines = 1, n_isles = 0 centroid = 2
  185. line = -1
  186. \endverbatim
  187. Isle I1 (see \ref P_isle)
  188. \verbatim
  189. isle = 1, n_lines = 1 area = 0
  190. line = 1
  191. \endverbatim
  192. <b>Areas with holes</b>
  193. \verbatim
  194. Three lines (nodes: 2, lines: 3, areas: 2, isles: 2)
  195. +N1
  196. / \
  197. / \
  198. / \
  199. / \
  200. / +L2 \
  201. / \
  202. / +N2 \
  203. / /\ \
  204. / / \ \
  205. / / \ \
  206. / ---L3-- \
  207. / \
  208. ------------L1-------------
  209. \endverbatim
  210. %Node N1 (see \ref P_node)
  211. \verbatim
  212. node = 1, n_lines = 2, xyz = 635720.081136, 225063.387424, 0.000000
  213. line = 1, type = 4 (GV_BOUNDARY), angle = -2.245537
  214. line = -1, type = 4 (GV_BOUNDARY), angle = -0.842926
  215. \endverbatim
  216. %Node N2 (see \ref P_node)
  217. \verbatim
  218. node = 2, n_lines = 2, xyz = 636788.032454, 223173.935091, 0.000000
  219. line = 3, type = 4 (GV_BOUNDARY), angle = -2.245537
  220. line = -3, type = 4 (GV_BOUNDARY), angle = -0.866302
  221. \endverbatim
  222. Line L1 (see \ref P_line)
  223. \verbatim
  224. line = 1, type = 4 (GV_BOUNDARY), n1 = 1, n2 = 1, left = 1, right = -1
  225. \endverbatim
  226. Line L2 (see \ref P_line)
  227. \verbatim
  228. line = 2, type = 8 (GV_CENTROID), area = 1
  229. \endverbatim
  230. Line L3 (see \ref P_line)
  231. \verbatim
  232. line = 3, type = 4 (GV_BOUNDARY), n1 = 3, n2 = 3, left = 2, right = -2
  233. \endverbatim
  234. Area A1 (see \ref P_area)
  235. \verbatim
  236. area = 1, n_lines = 1, n_isles = 1 centroid = 2
  237. line = -1
  238. isle = 2
  239. \endverbatim
  240. Area A2 (see \ref P_area)
  241. \verbatim
  242. area = 2, n_lines = 1, n_isles = 0 centroid = 0
  243. line = -3
  244. \endverbatim
  245. Isle I1 (see \ref P_isle)
  246. \verbatim
  247. isle = 1, n_lines = 1 area = 0
  248. line = 1
  249. \endverbatim
  250. Isle I2 (see \ref P_isle)
  251. \verbatim
  252. isle = 2, n_lines = 1 area = 1
  253. line = 3
  254. \endverbatim
  255. <b>Example 1</b>
  256. A polygon may be formed by many boundaries (several connected primitives).
  257. One boundary is shared by adjacent areas.
  258. \verbatim
  259. +--1--+--5--+
  260. | | |
  261. 2 A 4 B 6
  262. | | |
  263. +--3--+--7--+
  264. 1,2,3,4,5,6,7 = 7 boundaries (primitives)
  265. A,B = 2 areas
  266. A+B = 1 isle
  267. \endverbatim
  268. <b>Example 2</b>
  269. This is handled correctly in GRASS: A can be filled, B filled differently.
  270. \verbatim
  271. +---------+
  272. | A |
  273. +-----+ |
  274. | B | |
  275. +-----+ |
  276. | |
  277. +---------+
  278. A, B = 2 areas
  279. A+B = 1 isle
  280. \endverbatim
  281. In GRASS, whenever an 'inner' ring touches the boundary of an outside
  282. area, even in one point, it is no longer an 'inner' ring (isle in
  283. GRASS topology), it is simply another area. A, B above can never be
  284. exported from GRASS as polygon A with inner ring B because there are
  285. only 2 areas A and B and one island formed by A and B together.
  286. <b>Example 3</b>
  287. This is handled correctly in GRASS: Areas A1, A2, and A3 can be filled differently.
  288. \verbatim
  289. +---------------------+
  290. | A1 |
  291. + +------+------+ |
  292. | | A2 | A3 | |
  293. + +------+------+ |
  294. | I1 |
  295. +---------------------+
  296. A1,A2,A3 = 3 areas
  297. A1,A2+A3 = 2 isles
  298. \endverbatim
  299. In GRASS, whenever an 'inner' ring does not touch the boundary of an
  300. outside area, also not in one point, it is an 'inner' ring (isle). The
  301. areas A2 and A3 form a single isle I1 located within area A1. The size
  302. of isle I1 is substracted from the size of area A1 when calculating
  303. the size of area A1. Any centroids falling into isle I1 are excluded
  304. when searching for a centroid that can be attached to area A1. A1
  305. above can be exported from GRASS as polygon A1 with inner ring I1.
  306. <b>Example 4</b>
  307. <tt>v.in.ogr/v.clean</tt> can identify dangles and change the type
  308. from boundary to line (in TIGER data for example). Distinction
  309. between line and boundary isn't important only for dangles. Example:
  310. \verbatim
  311. +-----+-----+
  312. | . |
  313. | . |
  314. +.....+.....+
  315. | . |
  316. | x . |
  317. +-----+-----+
  318. ---- road + boundary of one parcel => type boundary
  319. .... road => type line
  320. x parcel centroid (identifies whole area)
  321. \endverbatim
  322. Because lines are not used to build areas, we have only one
  323. area/centroid, instead of 4 which would be necessary in TIGER.
  324. \subsection vlibTopoMemory Topology memory management
  325. Topology is generated for all kinds of vector types. Memory is not
  326. released by default. The programmer can force the library to release
  327. the memory by using Vect_set_release_support(). But: The programmer
  328. cannot run Vect_set_release_support() in mid process because all
  329. vectors are needed in the spatial index, which is needed to build topology.
  330. Topology is also necessary for points in case of a vector network
  331. because the graph is built using topology information about lines
  332. and points.
  333. The topology structure does not only store the topology but also
  334. the 'line' bounding box and line offset in coor file (index).
  335. The existing spatial index is using line ID in 'topology' structure
  336. to identify lines in 'coor' file. Currently it is not possible to build
  337. spatial index without topology.
  338. */