GRASS Programmer's Manual
6.5.svn(2014)-r66266
Main Page
Related Pages
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
rtree/test.c
Go to the documentation of this file.
1
2
/****************************************************************************
3
* MODULE: R-Tree library
4
*
5
* AUTHOR(S): Antonin Guttman - original code
6
* Daniel Green (green@superliminal.com) - major clean-up
7
* and implementation of bounding spheres
8
*
9
* PURPOSE: Multidimensional index
10
*
11
* COPYRIGHT: (C) 2001 by the GRASS Development Team
12
*
13
* This program is free software under the GNU General Public
14
* License (>=v2). Read the file COPYING that comes with GRASS
15
* for details.
16
*****************************************************************************/
17
18
#include <stdio.h>
19
#include "
index.h
"
20
21
struct
Rect
rects
[] = {
22
{{0, 0, 0, 2, 2, 0}},
/* xmin, ymin, zmin, xmax, ymax, zmax (for 3 dimensional RTree) */
23
{{5, 5, 0, 7, 7, 0}},
24
{{8, 5, 0, 9, 6, 0}},
25
{{7, 1, 0, 9, 2, 0}}
26
};
27
28
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 */
32
};
33
34
int
MySearchCallback
(
int
id
,
void
*arg)
35
{
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 */
39
}
40
41
int
main
()
42
{
43
struct
Node
*root =
RTreeNewIndex
();
44
int
i, nhits;
45
46
fprintf(stdout,
"nrects = %d\n"
,
nrects
);
47
/*
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.
56
*/
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);
61
62
return
0;
63
}
index.h
RTreeSearch
int RTreeSearch(struct Node *N, struct Rect *R, SearchHitCallback shcb, void *cbarg)
Definition:
vector/rtree/index.c:39
Node
Definition:
index.h:56
RTreeInsertRect
int RTreeInsertRect(struct Rect *R, int Tid, struct Node **Root, int Level)
Definition:
vector/rtree/index.c:138
nrects
int nrects
Definition:
rtree/test.c:29
main
int main(int argc, char *argv[])
Definition:
gem/main.c:302
rects
struct Rect rects[]
Definition:
rtree/test.c:21
RTreeNewIndex
struct Node * RTreeNewIndex(void)
Definition:
vector/rtree/index.c:25
MySearchCallback
int MySearchCallback(int id, void *arg)
Definition:
rtree/test.c:34
Rect
Definition:
index.h:40
search_rect
struct Rect search_rect
Definition:
rtree/test.c:30
lib
vector
rtree
test.c
Generated on Sat Jan 2 2016 01:46:49 for GRASS Programmer's Manual by
1.8.5