select.cpp 2.2 KB

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