rtree_search.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. \file lib/vector/Vlib/rtree_search.c
  3. \brief Vector library - simplified rtree search
  4. Higher level functions for reading/writing/manipulating vectors.
  5. (C) 2012 by the GRASS Development Team
  6. This program is free software under the GNU General Public License
  7. (>=v2). Read the file COPYING that comes with GRASS for details.
  8. \author Soeren Gebbert
  9. */
  10. #include <assert.h>
  11. #include <grass/vector.h>
  12. /* Function to add the ids of overlapping rectangles to an ilist
  13. * This function is a callback function used in RTreeSearch2()
  14. * */
  15. static int add_id_to_list(int id, const struct RTree_Rect *rect, void *list)
  16. {
  17. struct ilist *l = (struct ilist*)list;
  18. G_ilist_add(l, id);
  19. return 1;
  20. }
  21. /**
  22. * Search in an index tree for all data retangles that
  23. * overlap the argument rectangle.
  24. *
  25. * \param t: The RTree
  26. * \param r: The argument rectangle
  27. * \param list: The list to store the ids of overlapping rectangles
  28. * \return the number of qualifying data rects.
  29. */
  30. int RTreeSearch2(struct RTree *t, struct RTree_Rect *r, struct ilist *list)
  31. {
  32. assert(r && t);
  33. G_init_ilist(list);
  34. return t->search_rect(t, r, add_id_to_list, (void*)list);
  35. }