constraint.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*!
  2. \file lib/vector/Vlib/constraint.c
  3. \brief Vector library - constraints
  4. Higher level functions for reading/writing/manipulating vectors.
  5. These routines can affect the read_next_line funtions by
  6. restricting what they return. They are applied on a per map basis.
  7. These do not affect the lower level direct read functions.
  8. Normally, all 'Alive' lines will be returned unless overridden by
  9. this function. You can specified all the types you are interested
  10. in (by oring their types together). You can use this to say exclude
  11. Area type lines.
  12. By default all DEAD lines are ignored by the read_next_line ()
  13. functions This too can be overridden by including their types.
  14. Refer to dig_defines for the line type Defines
  15. All lines can be forced to be read by setting type = -1
  16. (C) 2001-2009 by the GRASS Development Team
  17. This program is free software under the GNU General Public License
  18. (>=v2). Read the file COPYING that comes with GRASS for details.
  19. \author Original author CERL, probably Dave Gerdes or Mike Higgins.
  20. \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
  21. \date 2001-2008
  22. */
  23. #include <grass/vector.h>
  24. /*!
  25. \brief Set constraint region
  26. \param Map vector map
  27. \param n,s,e,w,t,b north, south, east, west, top, bottom coordinates
  28. \return 0 on success
  29. \return -1 on error
  30. */
  31. int
  32. Vect_set_constraint_region(struct Map_info *Map,
  33. double n, double s, double e, double w, double t,
  34. double b)
  35. {
  36. if (n <= s)
  37. return -1;
  38. if (e <= w)
  39. return -1;
  40. Map->Constraint_region_flag = 1;
  41. Map->Constraint_box.N = n;
  42. Map->Constraint_box.S = s;
  43. Map->Constraint_box.E = e;
  44. Map->Constraint_box.W = w;
  45. Map->Constraint_box.T = t;
  46. Map->Constraint_box.B = b;
  47. Map->head.proj = G_projection();
  48. return 0;
  49. }
  50. /*!
  51. \brief Get constraint box
  52. \param Map vector map
  53. \param[out] Box bounding box
  54. \return 0
  55. */
  56. int Vect_get_constraint_box(const struct Map_info *Map, struct bound_box * Box)
  57. {
  58. Box->N = Map->Constraint_box.N;
  59. Box->S = Map->Constraint_box.S;
  60. Box->E = Map->Constraint_box.E;
  61. Box->W = Map->Constraint_box.W;
  62. Box->T = Map->Constraint_box.T;
  63. Box->B = Map->Constraint_box.B;
  64. return 0;
  65. }
  66. /*!
  67. \brief Set constraint type
  68. \param Map vector map
  69. \param type constraint type
  70. \return 0
  71. */
  72. int Vect_set_constraint_type(struct Map_info *Map, int type)
  73. {
  74. Map->Constraint_type = type;
  75. Map->Constraint_type_flag = 1;
  76. return 0;
  77. }
  78. /*!
  79. \brief Remove constraints
  80. \param Map vector map
  81. \return 0
  82. */
  83. int Vect_remove_constraints(struct Map_info *Map)
  84. {
  85. Map->Constraint_region_flag = 0;
  86. Map->Constraint_type_flag = 0;
  87. return 0;
  88. }