constraint.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*!
  2. \file 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. #include <grass/gis.h>
  25. /*!
  26. \brief Set constraint region
  27. \param Map vector map
  28. \param n,s,e,w,t,b north, south, east, west, top, bottom coordinates
  29. \return 0 on success
  30. \return -1 on error
  31. */
  32. int
  33. Vect_set_constraint_region(struct Map_info *Map,
  34. double n, double s, double e, double w, double t,
  35. double b)
  36. {
  37. if (n <= s)
  38. return -1;
  39. if (e <= w)
  40. return -1;
  41. Map->Constraint_region_flag = 1;
  42. Map->Constraint_N = n;
  43. Map->Constraint_S = s;
  44. Map->Constraint_E = e;
  45. Map->Constraint_W = w;
  46. Map->Constraint_T = t;
  47. Map->Constraint_B = b;
  48. Map->proj = G_projection();
  49. return 0;
  50. }
  51. /*!
  52. \brief Get constraint box
  53. \param Map vector map
  54. \param[out] Box bounding box
  55. \return 0
  56. */
  57. int Vect_get_constraint_box(const struct Map_info *Map, struct bound_box * Box)
  58. {
  59. Box->N = Map->Constraint_N;
  60. Box->S = Map->Constraint_S;
  61. Box->E = Map->Constraint_E;
  62. Box->W = Map->Constraint_W;
  63. Box->T = Map->Constraint_T;
  64. Box->B = Map->Constraint_B;
  65. return 0;
  66. }
  67. /*!
  68. \brief Set constraint type
  69. \param Map vector map
  70. \param type constraint type
  71. \return 0
  72. */
  73. int Vect_set_constraint_type(struct Map_info *Map, int type)
  74. {
  75. Map->Constraint_type = type;
  76. Map->Constraint_type_flag = 1;
  77. return 0;
  78. }
  79. /*!
  80. \brief Remove constraints
  81. \param Map vector map
  82. \return 0
  83. */
  84. int Vect_remove_constraints(struct Map_info *Map)
  85. {
  86. Map->Constraint_region_flag = 0;
  87. Map->Constraint_type_flag = 0;
  88. return 0;
  89. }