GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
rtree_search.c
Go to the documentation of this file.
1 /*!
2  \file lib/vector/Vlib/rtree_search.c
3 
4  \brief Vector library - simplified rtree search
5 
6  Higher level functions for reading/writing/manipulating vectors.
7 
8  (C) 2012 by the GRASS Development Team
9 
10  This program is free software under the GNU General Public License
11  (>=v2). Read the file COPYING that comes with GRASS for details.
12 
13  \author Soeren Gebbert
14  */
15 
16 #include <assert.h>
17 #include <grass/vector.h>
18 
19 /* Function to add the ids of overlapping rectangles to an ilist
20  * This function is a callback function used in RTreeSearch2()
21  * */
22 static int add_id_to_list(int id, const struct RTree_Rect *rect UNUSED,
23  void *list)
24 {
25  struct ilist *l = (struct ilist *)list;
26 
27  G_ilist_add(l, id);
28  return 1;
29 }
30 
31 /**
32  * Search in an index tree for all data rectangles that
33  * overlap the argument rectangle.
34  *
35  * \param t: The RTree
36  * \param r: The argument rectangle
37  * \param list: The list to store the ids of overlapping rectangles
38  * \return the number of qualifying data rects.
39  */
40 int RTreeSearch2(struct RTree *t, struct RTree_Rect *r, struct ilist *list)
41 {
42  assert(r && t);
43 
45 
46  return t->search_rect(t, r, add_id_to_list, (void *)list);
47 }
void G_init_ilist(struct ilist *)
Init an integer list and free allocated memory.
Definition: ilist.c:58
void G_ilist_add(struct ilist *, int)
Add item to ilist.
Definition: ilist.c:78
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition: gis.h:47
#define assert(condition)
Definition: lz4.c:291
double l
Definition: r_raster.c:39
double t
Definition: r_raster.c:39
double r
Definition: r_raster.c:39
int RTreeSearch2(struct RTree *t, struct RTree_Rect *r, struct ilist *list)
Definition: rtree_search.c:40
Definition: rtree.h:123
List of integers.
Definition: gis.h:709
Definition: manage.h:4