GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-b4e4cb0fe9
|
by GRASS Development Team (https://grass.osgeo.org)
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):
In general it is possible to free the memory with Vect_set_release_support() such as:
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:
See also spatial_index data structure.
Spatial index file ('sidx') is read by Vect_open_sidx().
Note: plus
is instance of 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 |
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 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.
Category index file ('cidx') is read by Vect_cidx_open().
Note: plus
is instance of Plus_head structure.
Name | Type | Number | Description |
plus->cpidx_Version_Major | C | 1 | file version (major) |
plus->cpidx_Version_Minor | C | 1 | file version (minor) |
plus->cpidx_Back_Major | C | 1 | supported from GRASS version (major) |
plus->cpidx_Back_Minor | C | 1 | supported from GRASS version (minor) |
plus->cidx_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->cidx_head_size | L | 1 | cidx head size |
plus->n_cidx | I | 1 | number of fields |
field | I | n_cidx | field number |
n_cats | I | n_cidx | number of categories |
n_ucats | I | n_cidx | number of unique categories |
n_types | I | n_cidx | number of feature types |
rtype | I | n_cidx * n_types | Feature type |
type[t] | I | n_cidx * n_types | Number of items |