select.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. \file select.cpp
  3. \brief Select lines (by query)
  4. This program is free software under the GNU General Public
  5. License (>=v2). Read the file COPYING that comes with GRASS
  6. for details.
  7. (C) 2008 by The GRASS development team
  8. \author Martin Landa <landa.martin gmail.com>
  9. \date 2008
  10. */
  11. extern "C" {
  12. #include <grass/vedit.h>
  13. }
  14. #include "driver.h"
  15. #include "digit.h"
  16. /**
  17. \brief Select features by query (based on geometry)
  18. Currently supported:
  19. - QUERY_LENGTH, select all lines longer then threshold (or shorter if threshold is negative)
  20. - QUERY_DANGLE, select all dangles then threshold (or shorter if threshold is negative)
  21. \todo Rewrite dangle part to use Vector library functionality
  22. \todo 3D
  23. \param x1,y1,z1,x2,y2,z2 bounding box
  24. \param query query (length, dangle, ...)
  25. \param thresh threshold value (< 0 for 'shorter', > 0 for 'longer')
  26. \param type feature type
  27. \param box query features in bounding box
  28. \return list of selected features
  29. */
  30. std::vector<int> Digit::SelectLinesByQuery(double x1, double y1, double z1,
  31. double x2, double y2, double z2, bool box,
  32. int query, int type, double thresh)
  33. {
  34. int layer;
  35. std::vector<int> ids;
  36. struct ilist *List;
  37. struct line_pnts *bbox;
  38. if (!display->mapInfo) {
  39. display->DisplayMsg();
  40. return ids;
  41. }
  42. layer = 1; // TODO
  43. bbox = NULL;
  44. List = Vect_new_list();
  45. if (box) {
  46. bbox = Vect_new_line_struct();
  47. Vect_append_point(bbox, x1, y1, z1);
  48. Vect_append_point(bbox, x2, y1, z2);
  49. Vect_append_point(bbox, x2, y2, z1);
  50. Vect_append_point(bbox, x1, y2, z2);
  51. Vect_append_point(bbox, x1, y1, z1);
  52. Vect_select_lines_by_polygon (display->mapInfo, bbox, 0, NULL, type, List);
  53. if (List->n_values == 0) {
  54. return ids;
  55. }
  56. }
  57. G_debug(3, "wxDigit.SelectLinesByQuery(): lines=%d", List->n_values);
  58. Vedit_select_by_query(display->mapInfo,
  59. type, layer, thresh, query,
  60. List);
  61. ids = display->ListToVector(List); // TODO
  62. G_debug(3, "wxDigit.SelectLinesByQuery(): lines=%d", List->n_values);
  63. Vect_destroy_list(List);
  64. if (bbox) {
  65. Vect_destroy_line_struct(bbox);
  66. }
  67. return ids;
  68. }