1
/*! \page vlibIndices Spatial and category indices
3
by GRASS Development Team (http://grass.osgeo.org)
7
\section vlibSpidx Vector library spatial index management
9
Spatial index (based on R*-tree) is created with topology.
11
Spatial index occupies a lot of memory but it is necessary for
12
topology building. Also, it takes some time to release the memory
13
occupied by spatial index (see dig_spidx_free()). The spatial index can
14
also be built in file to save memory by setting the environment variable
17
The function building topology - Vect_build() - is usually called at
18
the end of modules (before Vect_close()) so it is faster to call
19
<tt>exit()</tt> and operating system releases all the memory much
20
faster. By default the memory is not released.
22
It is possible to call Vect_set_release_support() before Vect_close()
23
to enforce memory release, but it takes some time on large files.
25
The spatial index is stored in file and not loaded for old vectors that
26
are not updated, saving a lot of memory. Spatial queries are done in
29
Currently most of the modules do not release the memory occupied for
30
spatial index and work like this (pseudocode):
36
/* writing new vector */
39
Vect_close(); /* memory is not released */
43
In general it is possible to free the memory with Vect_set_release_support()
50
/* writing new vector */
53
Vect_set_release_support();
54
Vect_close(); /* memory is released */
58
but it takes a bit longer.
60
It makes sense to release the spatial index if it is used only at the beginning
61
of a module or in permanently running programs like QGIS. Note that this
62
applies only when creating a new vector or updating an old vector.
69
/* select features using spatial index, e.g. Vect_select_lines_by_box() */
70
Vect_set_release_support();
71
Vect_close(); /* memory is released */
73
/* do some processing which needs memory */
77
See also \ref spatial_index data structure.
79
\subsection vlibSidxFileFormat Sidx file format specification
81
Spatial index file ('sidx') is read by Vect_open_sidx().
83
\subsubsection vlibSidxFileHead Header
85
Note: <tt>plus</tt> is instance of \ref Plus_head structure.
87
<table border="1" style="border-collapse: collapse" cellpadding="5">
88
<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
90
<tr><td>plus->spidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
91
<tr><td>plus->spidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
92
<tr><td>plus->spidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
93
<tr><td>plus->spidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
95
<tr><td>plus->spidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
96
flag; files are written in machine native order but
97
files in both little and big endian order may be
98
readl; zero for little endian</td></tr>
100
<tr><td>plus->spidx_port.off_t_size</td><td>C</td><td>1</td><td>off_t size (LFS)</td></tr>
102
<tr><td>plus->spidx_head_size</td><td>L</td><td>1</td><td>header size</td></tr>
104
<tr><td>plus->spidx_with_z</td><td>C</td><td>1</td><td>2D/3D vector data</td></tr>
106
<tr><td>ndims</td><td>C</td><td>1</td><td>Number of dimensions</td></tr>
108
<tr><td>nsides</td><td>C</td><td>1</td><td>Number of sides</td></tr>
110
<tr><td>nodesize</td><td>I</td><td>1</td><td>%Node size</td></tr>
112
<tr><td>nodecard</td><td>I</td><td>1</td><td>%Node card (?)</td></tr>
114
<tr><td>leafcard</td><td>I</td><td>1</td><td>Leaf card (?)</td></tr>
116
<tr><td>min_node_fill</td><td>I</td><td>1</td><td>Minimum node fill (?)</td></tr>
118
<tr><td>min_leaf_fill</td><td>I</td><td>1</td><td>Minimum leaf fill (?)</td></tr>
120
<tr><td>plus->Node_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
122
<tr><td>plus->Node_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
124
<tr><td>plus->Node_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
126
<tr><td>plus->Node_spidx_offset</td><td>O</td><td>1</td><td>%Node offset</td></tr>
128
<tr><td>plus->Line_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
130
<tr><td>plus->Line_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
132
<tr><td>plus->Line_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
134
<tr><td>plus->Line_spidx_offset</td><td>O</td><td>1</td><td>Line offset</td></tr>
136
<tr><td>plus->Area_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
138
<tr><td>plus->Area_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
140
<tr><td>plus->Area_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
142
<tr><td>plus->Area_spidx_offset</td><td>O</td><td>1</td><td>Area offset</td></tr>
144
<tr><td>plus->Isle_spidx->n_nodes</td><td>I</td><td>1</td><td>Number of nodes</td></tr>
146
<tr><td>plus->Isle_spidx->n_leafs</td><td>I</td><td>1</td><td>Number of leafs</td></tr>
148
<tr><td>plus->Isle_spidx->n_levels</td><td>I</td><td>1</td><td>Number of levels</td></tr>
150
<tr><td>plus->Isle_spidx_offset</td><td>O</td><td>1</td><td>Isle offset</td></tr>
152
<tr><td>plus->Face_spidx_offset</td><td>O</td><td>1</td><td>Face offset</td></tr>
154
<tr><td>plus->Volume_spidx_offset</td><td>O</td><td>1</td><td>Volume offset</td></tr>
156
<tr><td>plus->Hole_spidx_offset</td><td>O</td><td>1</td><td>Hole offset</td></tr>
158
<tr><td>plus->coor_size</td><td>O</td><td>1</td><td>Coor file size</td></tr>
161
\section vlibCidx Vector library category index management
163
The category index (stored in the cidx file) improves the performance
164
of all selections by cats/attributes (SQL, e.g. <tt>d.vect
165
cats=27591</tt>, <tt>v.extract list=20000-21000</tt>). This avoids
166
that all selections have to be made by looping through all vector
167
lines. Category index is also essential for simple feature
168
representation of GRASS vectors.
170
Category index is created for each field. In memory, it is stored in
171
\ref Cat_index data structure.
173
Category index is built with topology, but it is <b>not updated</b> if
174
vector is edited on level 2. Category index is stored in 'cidx' file,
175
'cat' array is written/read by one call of dig__fwrite_port_I() or
178
Stored values can be retrieved either by index in 'cat' array (if all
179
features of given field are required) or by category value (one or few
180
features), always by <tt>Vect_cidx_*()</tt> functions.
182
To create category index, it will be necessary to rebuild topology for
183
all existing vectors. This is an opportunity to make (hopefully) last
184
changes in 'topo', 'cidx' formats.
186
\subsection vlibCidxFileFormat Cidx file format specification
188
Category index file ('cidx') is read by Vect_cidx_open().
190
\subsubsection vlibCidxFileHead Header
192
Note: <tt>plus</tt> is instance of \ref Plus_head structure.
194
<table border="1" style="border-collapse: collapse" cellpadding="5">
195
<tr><td><b>Name</b></td><td><b>Type</b></td><td><b>Number</b></td><td><b>Description</b></td></tr>
197
<tr><td>plus->cpidx_Version_Major </td><td>C</td><td>1</td><td>file version (major)</td></tr>
198
<tr><td>plus->cpidx_Version_Minor </td><td>C</td><td>1</td><td>file version (minor)</td></tr>
199
<tr><td>plus->cpidx_Back_Major</td><td>C</td><td>1</td><td>supported from GRASS version (major)</td></tr>
200
<tr><td>plus->cpidx_Back_Minor</td><td>C</td><td>1</td><td>supported from GRASS version (minor)</td></tr>
202
<tr><td>plus->cidx_port->byte_order</td><td>C</td><td>1</td><td>little or big endian
203
flag; files are written in machine native order but
204
files in both little and big endian order may be
205
readl; zero for little endian</td></tr>
207
<tr><td>plus->cidx_head_size</td><td>L</td><td>1</td><td>cidx head size</td></tr>
209
<tr><td>plus->n_cidx</td><td>I</td><td>1</td><td>number of fields</td></tr>
211
<tr><td>field</td><td>I</td><td>n_cidx</td><td>field number</td></tr>
213
<tr><td>n_cats</td><td>I</td><td>n_cidx</td><td>number of categories</td></tr>
215
<tr><td>n_ucats</td><td>I</td><td>n_cidx</td><td>number of unique categories</td></tr>
217
<tr><td>n_types</td><td>I</td><td>n_cidx</td><td>number of feature types</td></tr>
219
<tr><td>rtype</td><td>I</td><td>n_cidx * n_types</td><td>Feature type</td></tr>
221
<tr><td>type[t]</td><td>I</td><td>n_cidx * n_types</td><td>Number of items</td></tr>