vectorlib_topology.dox 13 KB

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