constraint.c 2.7 KB

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