/*! \page vlibIndices Spatial and category indices
by GRASS Development Team (https://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.
Name | Type | Number | Description |
plus->spidx_Version_Major | C | 1 | file version (major) |
plus->spidx_Version_Minor | C | 1 | file version (minor) |
plus->spidx_Back_Major | C | 1 | supported from GRASS version (major) |
plus->spidx_Back_Minor | C | 1 | supported from GRASS version (minor) |
plus->spidx_port->byte_order | C | 1 | little 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_size | C | 1 | off_t size (LFS) |
plus->spidx_head_size | L | 1 | header size |
plus->spidx_with_z | C | 1 | 2D/3D vector data |
ndims | C | 1 | Number of dimensions |
nsides | C | 1 | Number of sides |
nodesize | I | 1 | %Node size |
nodecard | I | 1 | %Node card (?) |
leafcard | I | 1 | Leaf card (?) |
min_node_fill | I | 1 | Minimum node fill (?) |
min_leaf_fill | I | 1 | Minimum leaf fill (?) |
plus->Node_spidx->n_nodes | I | 1 | Number of nodes |
plus->Node_spidx->n_leafs | I | 1 | Number of leafs |
plus->Node_spidx->n_levels | I | 1 | Number of levels |
plus->Node_spidx_offset | O | 1 | %Node offset |
plus->Line_spidx->n_nodes | I | 1 | Number of nodes |
plus->Line_spidx->n_leafs | I | 1 | Number of leafs |
plus->Line_spidx->n_levels | I | 1 | Number of levels |
plus->Line_spidx_offset | O | 1 | Line offset |
plus->Area_spidx->n_nodes | I | 1 | Number of nodes |
plus->Area_spidx->n_leafs | I | 1 | Number of leafs |
plus->Area_spidx->n_levels | I | 1 | Number of levels |
plus->Area_spidx_offset | O | 1 | Area offset |
plus->Isle_spidx->n_nodes | I | 1 | Number of nodes |
plus->Isle_spidx->n_leafs | I | 1 | Number of leafs |
plus->Isle_spidx->n_levels | I | 1 | Number of levels |
plus->Isle_spidx_offset | O | 1 | Isle offset |
plus->Face_spidx_offset | O | 1 | Face offset |
plus->Volume_spidx_offset | O | 1 | Volume offset |
plus->Hole_spidx_offset | O | 1 | Hole offset |
plus->coor_size | O | 1 | Coor 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.