/*! \page vlibIndices Spatial and category indices by GRASS Development Team (http://grass.osgeo.org) \tableofcontents \section vlibSpidx Vector library spatial index management Spatial index (based on R*-tree) is created with topology. Spatial index occupies a lot of memory but it is necessary for topology building. Also, it takes some time to release the memory occupied by spatial index (see dig_spidx_free()). The spatial index can also be built in file to save memory by setting the environment variable GRASS_VECTOR_LOWMEM. The function building topology - Vect_build() - is usually called at the end of modules (before Vect_close()) so it is faster to call exit() and operating system releases all the memory much faster. By default the memory is not released. It is possible to call Vect_set_release_support() before Vect_close() to enforce memory release, but it takes some time on large files. The spatial index is stored in file and not loaded for old vectors that are not updated, saving a lot of memory. Spatial queries are done in file. Currently most of the modules do not release the memory occupied for spatial index and work like this (pseudocode): \code int main { Vect_open_new(); /* writing new vector */ Vect_build(); Vect_close(); /* memory is not released */ } \endcode In general it is possible to free the memory with Vect_set_release_support() such as: \code int main { Vect_open_new(); /* writing new vector */ Vect_build(); Vect_set_release_support(); Vect_close(); /* memory is released */ } \endcode but it takes a bit longer. It makes sense to release the spatial index if it is used only at the beginning of a module or in permanently running programs like QGIS. Note that this applies only when creating a new vector or updating an old vector. For example: \code int main { Vect_open_update(); /* select features using spatial index, e.g. Vect_select_lines_by_box() */ Vect_set_release_support(); Vect_close(); /* memory is released */ /* do some processing which needs memory */ } \endcode See also \ref spatial_index data structure. \subsection vlibSidxFileFormat Sidx file format specification Spatial index file ('sidx') is read by Vect_open_sidx(). \subsubsection vlibSidxFileHead Header Note: plus is instance of \ref Plus_head structure.
NameTypeNumberDescription
plus->spidx_Version_Major C1file version (major)
plus->spidx_Version_Minor C1file version (minor)
plus->spidx_Back_MajorC1supported from GRASS version (major)
plus->spidx_Back_MinorC1supported from GRASS version (minor)
plus->spidx_port->byte_orderC1little or big endian flag; files are written in machine native order but files in both little and big endian order may be readl; zero for little endian
plus->spidx_port.off_t_sizeC1off_t size (LFS)
plus->spidx_head_sizeL1header size
plus->spidx_with_zC12D/3D vector data
ndimsC1Number of dimensions
nsidesC1Number of sides
nodesizeI1%Node size
nodecardI1%Node card (?)
leafcardI1Leaf card (?)
min_node_fillI1Minimum node fill (?)
min_leaf_fillI1Minimum leaf fill (?)
plus->Node_spidx->n_nodesI1Number of nodes
plus->Node_spidx->n_leafsI1Number of leafs
plus->Node_spidx->n_levelsI1Number of levels
plus->Node_spidx_offsetO1%Node offset
plus->Line_spidx->n_nodesI1Number of nodes
plus->Line_spidx->n_leafsI1Number of leafs
plus->Line_spidx->n_levelsI1Number of levels
plus->Line_spidx_offsetO1Line offset
plus->Area_spidx->n_nodesI1Number of nodes
plus->Area_spidx->n_leafsI1Number of leafs
plus->Area_spidx->n_levelsI1Number of levels
plus->Area_spidx_offsetO1Area offset
plus->Isle_spidx->n_nodesI1Number of nodes
plus->Isle_spidx->n_leafsI1Number of leafs
plus->Isle_spidx->n_levelsI1Number of levels
plus->Isle_spidx_offsetO1Isle offset
plus->Face_spidx_offsetO1Face offset
plus->Volume_spidx_offsetO1Volume offset
plus->Hole_spidx_offsetO1Hole offset
plus->coor_sizeO1Coor file size
\section vlibCidx Vector library category index management The category index (stored in the cidx file) improves the performance of all selections by cats/attributes (SQL, e.g. d.vect cats=27591, v.extract list=20000-21000). This avoids that all selections have to be made by looping through all vector lines. Category index is also essential for simple feature representation of GRASS vectors. Category index is created for each field. In memory, it is stored in \ref Cat_index data structure. Category index is built with topology, but it is not updated if vector is edited on level 2. Category index is stored in 'cidx' file, 'cat' array is written/read by one call of dig__fwrite_port_I() or dig__fread_port_I(). Stored values can be retrieved either by index in 'cat' array (if all features of given field are required) or by category value (one or few features), always by Vect_cidx_*() functions. To create category index, it will be necessary to rebuild topology for all existing vectors. This is an opportunity to make (hopefully) last changes in 'topo', 'cidx' formats. \subsection vlibCidxFileFormat Cidx file format specification Category index file ('cidx') is read by Vect_cidx_open(). \subsubsection vlibCidxFileHead Header Note: plus is instance of \ref Plus_head structure.
NameTypeNumberDescription
plus->cpidx_Version_Major C1file version (major)
plus->cpidx_Version_Minor C1file version (minor)
plus->cpidx_Back_MajorC1supported from GRASS version (major)
plus->cpidx_Back_MinorC1supported from GRASS version (minor)
plus->cidx_port->byte_orderC1little or big endian flag; files are written in machine native order but files in both little and big endian order may be readl; zero for little endian
plus->cidx_head_sizeL1cidx head size
plus->n_cidxI1number of fields
fieldIn_cidxfield number
n_catsIn_cidxnumber of categories
n_ucatsIn_cidxnumber of unique categories
n_typesIn_cidxnumber of feature types
rtypeIn_cidx * n_typesFeature type
type[t]In_cidx * n_typesNumber of items
*/