2
/****************************************************************************
3
* MODULE: R-Tree library
5
* AUTHOR(S): Antonin Guttman - original code
6
* Daniel Green (green@superliminal.com) - major clean-up
7
* and implementation of bounding spheres
9
* PURPOSE: Multidimensional index
11
* COPYRIGHT: (C) 2001 by the GRASS Development Team
13
* This program is free software under the GNU General Public
14
* License (>=v2). Read the file COPYING that comes with GRASS
16
*****************************************************************************/
21
struct Rect rects[] = {
22
{{0, 0, 0, 2, 2, 0}}, /* xmin, ymin, zmin, xmax, ymax, zmax (for 3 dimensional RTree) */
29
int nrects = sizeof(rects) / sizeof(rects[0]);
30
struct Rect search_rect = {
31
{6, 4, 0, 10, 6, 0} /* search will find above rects that this one overlaps */
34
int MySearchCallback(int id, void *arg)
36
/* Note: -1 to make up for the +1 when data was inserted */
37
fprintf(stdout, "Hit data rect %d\n", id - 1);
38
return 1; /* keep going */
43
struct Node *root = RTreeNewIndex();
46
fprintf(stdout, "nrects = %d\n", nrects);
48
* Insert all the data rects.
49
* Notes about the arguments:
50
* parameter 1 is the rect being inserted,
51
* parameter 2 is its ID. NOTE: *** ID MUST NEVER BE ZERO ***, hence the +1,
52
* parameter 3 is the root of the tree. Note: its address is passed
53
* because it can change as a result of this call, therefore no other parts
54
* of this code should stash its address since it could change undernieth.
55
* parameter 4 is always zero which means to add from the root.
57
for (i = 0; i < nrects; i++)
58
RTreeInsertRect(&rects[i], i + 1, &root, 0); /* i+1 is rect ID. Note: root can change */
59
nhits = RTreeSearch(root, &search_rect, MySearchCallback, 0);
60
fprintf(stdout, "Search resulted in %d hits\n", nhits);