vectorlib_indices.dox 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*! \page vlibIndices Spatial and category indices
  2. by GRASS Development Team (http://grass.osgeo.org)
  3. \tableofcontents
  4. \section vlibSpidx Vector library spatial index management
  5. Spatial index (based on R*-tree) is created with topology.
  6. Spatial index occupies a lot of memory but it is necessary for
  7. topology building. Also, it takes some time to release the memory
  8. occupied by spatial index (see dig_spidx_free()). The spatial index can
  9. also be built in file to save memory by setting the environment variable
  10. GRASS_VECTOR_LOWMEM.
  11. The function building topology - Vect_build() - is usually called at
  12. the end of modules (before Vect_close()) so it is faster to call
  13. <tt>exit()</tt> and operating system releases all the memory much
  14. faster. By default the memory is not released.
  15. It is possible to call Vect_set_release_support() before Vect_close()
  16. to enforce memory release, but it takes some time on large files.
  17. The spatial index is stored in file and not loaded for old vectors that
  18. are not updated, saving a lot of memory. Spatial queries are done in
  19. file.
  20. Currently most of the modules do not release the memory occupied for
  21. spatial index and work like this (pseudocode):
  22. \code
  23. int main
  24. {
  25. Vect_open_new();
  26. /* writing new vector */
  27. Vect_build();
  28. Vect_close(); /* memory is not released */
  29. }
  30. \endcode
  31. In general it is possible to free the memory with Vect_set_release_support()
  32. such as:
  33. \code
  34. int main
  35. {
  36. Vect_open_new();
  37. /* writing new vector */
  38. Vect_build();
  39. Vect_set_release_support();
  40. Vect_close(); /* memory is released */
  41. }
  42. \endcode
  43. but it takes a bit longer.
  44. It makes sense to release the spatial index if it is used only at the beginning
  45. of a module or in permanently running programs like QGIS. Note that this
  46. applies only when creating a new vector or updating an old vector.
  47. For example:
  48. \code
  49. int main
  50. {
  51. Vect_open_update();
  52. /* select features using spatial index, e.g. Vect_select_lines_by_box() */
  53. Vect_set_release_support();
  54. Vect_close(); /* memory is released */
  55. /* do some processing which needs memory */
  56. }
  57. \endcode
  58. See also \ref spatial_index data structure.
  59. \subsection vlibSidxFileFormat Sidx file format specification
  60. Spatial index file ('sidx') is read by Vect_open_sidx().
  61. \subsubsection vlibSidxFileHead Header
  62. Note: <tt>plus</tt> is instance of \ref Plus_head structure.
  63. <table border="1" style="border-collapse: collapse" cellpadding="5">
  64. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  65. <tr><td>plus->spidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  66. <tr><td>plus->spidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  67. <tr><td>plus->spidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  68. <tr><td>plus->spidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  69. <tr><td>plus->spidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  70. flag; files are written in machine native order but
  71. files in both little and big endian order may be
  72. readl; zero for little endian</td></tr>
  73. <tr><td>plus->spidx_port.off_t_size</td><td>C</td><td>1</td><td>off_t size (LFS)</td></tr>
  74. <tr><td>plus->spidx_head_size</td><td>L</td><td>1</td><td>header size</td></tr>
  75. <tr><td>plus->spidx_with_z</td><td>C</td><td>1</td><td>2D/3D vector data</td></tr>
  76. <tr><td>ndims</td><td>C</td><td>1</td><td>Number of dimensions</td></tr>
  77. <tr><td>nsides</td><td>C</td><td>1</td><td>Number of sides</td></tr>
  78. <tr><td>nodesize</td><td>I</td><td>1</td><td>%Node size</td></tr>
  79. <tr><td>nodecard</td><td>I</td><td>1</td><td>%Node card (?)</td></tr>
  80. <tr><td>leafcard</td><td>I</td><td>1</td><td>Leaf card (?)</td></tr>
  81. <tr><td>min_node_fill</td><td>I</td><td>1</td><td>Minimum node fill (?)</td></tr>
  82. <tr><td>min_leaf_fill</td><td>I</td><td>1</td><td>Minimum leaf fill (?)</td></tr>
  83. <tr><td>plus->Node_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  84. <tr><td>plus->Node_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  85. <tr><td>plus->Node_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  86. <tr><td>plus->Node_spidx_offset</td><td>O</td><td>1</td><td>%Node offset</td></tr>
  87. <tr><td>plus->Line_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  88. <tr><td>plus->Line_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  89. <tr><td>plus->Line_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  90. <tr><td>plus->Line_spidx_offset</td><td>O</td><td>1</td><td>Line offset</td></tr>
  91. <tr><td>plus->Area_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  92. <tr><td>plus->Area_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  93. <tr><td>plus->Area_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  94. <tr><td>plus->Area_spidx_offset</td><td>O</td><td>1</td><td>Area offset</td></tr>
  95. <tr><td>plus->Isle_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
  96. <tr><td>plus->Isle_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
  97. <tr><td>plus->Isle_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
  98. <tr><td>plus->Isle_spidx_offset</td><td>O</td><td>1</td><td>Isle offset</td></tr>
  99. <tr><td>plus->Face_spidx_offset</td><td>O</td><td>1</td><td>Face offset</td></tr>
  100. <tr><td>plus->Volume_spidx_offset</td><td>O</td><td>1</td><td>Volume offset</td></tr>
  101. <tr><td>plus->Hole_spidx_offset</td><td>O</td><td>1</td><td>Hole offset</td></tr>
  102. <tr><td>plus->coor_size</td><td>O</td><td>1</td><td>Coor file size</td></tr>
  103. </table>
  104. \section vlibCidx Vector library category index management
  105. The category index (stored in the cidx file) improves the performance
  106. of all selections by cats/attributes (SQL, e.g. <tt>d.vect
  107. cats=27591</tt>, <tt>v.extract list=20000-21000</tt>). This avoids
  108. that all selections have to be made by looping through all vector
  109. lines. Category index is also essential for simple feature
  110. representation of GRASS vectors.
  111. Category index is created for each field. In memory, it is stored in
  112. \ref Cat_index data structure.
  113. Category index is built with topology, but it is <b>not updated</b> if
  114. vector is edited on level 2. Category index is stored in 'cidx' file,
  115. 'cat' array is written/read by one call of dig__fwrite_port_I() or
  116. dig__fread_port_I().
  117. Stored values can be retrieved either by index in 'cat' array (if all
  118. features of given field are required) or by category value (one or few
  119. features), always by <tt>Vect_cidx_*()</tt> functions.
  120. To create category index, it will be necessary to rebuild topology for
  121. all existing vectors. This is an opportunity to make (hopefully) last
  122. changes in 'topo', 'cidx' formats.
  123. \subsection vlibCidxFileFormat Cidx file format specification
  124. Category index file ('cidx') is read by Vect_cidx_open().
  125. \subsubsection vlibCidxFileHead Header
  126. Note: <tt>plus</tt> is instance of \ref Plus_head structure.
  127. <table border="1" style="border-collapse: collapse" cellpadding="5">
  128. <tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
  129. <tr><td>plus->cpidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
  130. <tr><td>plus->cpidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
  131. <tr><td>plus->cpidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
  132. <tr><td>plus->cpidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
  133. <tr><td>plus->cidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
  134. flag; files are written in machine native order but
  135. files in both little and big endian order may be
  136. readl; zero for little endian</td></tr>
  137. <tr><td>plus->cidx_head_size</td><td>L</td><td>1</td><td>cidx head size</td></tr>
  138. <tr><td>plus->n_cidx</td><td>I</td><td>1</td><td>number of fields</td></tr>
  139. <tr><td>field</td><td>I</td><td>n_cidx</td><td>field number</td></tr>
  140. <tr><td>n_cats</td><td>I</td><td>n_cidx</td><td>number of categories</td></tr>
  141. <tr><td>n_ucats</td><td>I</td><td>n_cidx</td><td>number of unique categories</td></tr>
  142. <tr><td>n_types</td><td>I</td><td>n_cidx</td><td>number of feature types</td></tr>
  143. <tr><td>rtype</td><td>I</td><td>n_cidx * n_types</td><td>Feature type</td></tr>
  144. <tr><td>type[t]</td><td>I</td><td>n_cidx * n_types</td><td>Number of items</td></tr>
  145. </table>
  146. */