瀏覽代碼

vlib: update Vect_*_constraint_*() fns
introduce Vect_set_constraint_field()


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@49224 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 13 年之前
父節點
當前提交
f474b91c29
共有 1 個文件被更改,包括 78 次插入42 次删除
  1. 78 42
      lib/vector/Vlib/constraint.c

+ 78 - 42
lib/vector/Vlib/constraint.c

@@ -5,7 +5,7 @@
 
    Higher level functions for reading/writing/manipulating vectors.
 
-   These routines can affect the read_next_line funtions by
+   These routines can affect the Vect_read_next_line() funtions by
    restricting what they return. They are applied on a per map basis.
 
    These do not affect the lower level direct read functions.
@@ -13,24 +13,18 @@
    Normally, all 'Alive' lines will be returned unless overridden by
    this function. You can specified all the types you are interested
    in (by oring their types together). You can use this to say exclude
-   Area type lines.
+   'boundary' type features.
 
-   By default all DEAD lines are ignored by the read_next_line ()
-   functions This too can be overridden by including their types.
+   By default all DEAD lines are ignored by the Vect_read_next_line()
+   functions. This too can be overridden by including their types.
 
-   Refer to dig_defines for the line type Defines
-
-   All lines can be forced to be read by setting type = -1
-
-   (C) 2001-2009 by the GRASS Development Team
+   (C) 2001-2009, 2011 by the GRASS Development Team
 
    This program is free software under the GNU General Public License
-   (>=v2).  Read the file COPYING that comes with GRASS for details.
+   (>=v2). Read the file COPYING that comes with GRASS for details.
 
    \author Original author CERL, probably Dave Gerdes or Mike Higgins.
    \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
-
-   \date 2001-2008
  */
 
 #include <grass/vector.h>
@@ -38,50 +32,58 @@
 /*!
    \brief Set constraint region
 
-   \param Map vector map
-   \param n,s,e,w,t,b north, south, east, west, top, bottom coordinates
+   Vect_read_next_line() will read only features inside of given
+   region.
 
+   \param Map vector map
+   \param n,s,e,w,t,b north, south, east, west, top, and bottom coordinates
+   
    \return 0 on success
-   \return -1 on error
+   \return -1 on error (invalid region)
  */
-int
-Vect_set_constraint_region(struct Map_info *Map,
-			   double n, double s, double e, double w, double t,
-			   double b)
+int Vect_set_constraint_region(struct Map_info *Map,
+			       double n, double s, double e, double w,
+			       double t, double b)
 {
     if (n <= s)
 	return -1;
     if (e <= w)
 	return -1;
 
-    Map->Constraint_region_flag = 1;
-    Map->Constraint_box.N = n;
-    Map->Constraint_box.S = s;
-    Map->Constraint_box.E = e;
-    Map->Constraint_box.W = w;
-    Map->Constraint_box.T = t;
-    Map->Constraint_box.B = b;
+    Map->constraint.region_flag = TRUE;
+    Map->constraint.box.N = n;
+    Map->constraint.box.S = s;
+    Map->constraint.box.E = e;
+    Map->constraint.box.W = w;
+    Map->constraint.box.T = t;
+    Map->constraint.box.B = b;
     Map->head.proj = G_projection();
 
     return 0;
 }
 
 /*!
-   \brief Get constraint box
+   \brief Get constraint box 
+
+   Constraint box can be defined by Vect_set_constraint_region().
 
    \param Map vector map
    \param[out] Box bounding box
 
-   \return 0
+   \return 0 on success
+   \return -1 no region constraint defined
  */
 int Vect_get_constraint_box(const struct Map_info *Map, struct bound_box * Box)
 {
-    Box->N = Map->Constraint_box.N;
-    Box->S = Map->Constraint_box.S;
-    Box->E = Map->Constraint_box.E;
-    Box->W = Map->Constraint_box.W;
-    Box->T = Map->Constraint_box.T;
-    Box->B = Map->Constraint_box.B;
+    if (!Map->constraint.region_flag)
+	return -1;
+	    
+    Box->N = Map->constraint.box.N;
+    Box->S = Map->constraint.box.S;
+    Box->E = Map->constraint.box.E;
+    Box->W = Map->constraint.box.W;
+    Box->T = Map->constraint.box.T;
+    Box->B = Map->constraint.box.B;
 
     return 0;
 }
@@ -89,15 +91,21 @@ int Vect_get_constraint_box(const struct Map_info *Map, struct bound_box * Box)
 /*!
    \brief Set constraint type
 
+   Vect_read_next_line() will read only features of given type.
+
    \param Map vector map
-   \param type constraint type
+   \param type constraint type (GV_POINT, GV_LINE, ...)
 
-   \return 0
- */
+   \return 0 on success
+   \return -1 invalid feature type
+*/
 int Vect_set_constraint_type(struct Map_info *Map, int type)
 {
-    Map->Constraint_type = type;
-    Map->Constraint_type_flag = 1;
+    if (!(type & (GV_POINTS | GV_LINES | GV_FACE | GV_KERNEL)))
+	return -1;
+    
+    Map->constraint.type = type;
+    Map->constraint.type_flag = TRUE;
 
     return 0;
 }
@@ -109,10 +117,38 @@ int Vect_set_constraint_type(struct Map_info *Map, int type)
 
    \return 0
  */
-int Vect_remove_constraints(struct Map_info *Map)
+void Vect_remove_constraints(struct Map_info *Map)
 {
-    Map->Constraint_region_flag = 0;
-    Map->Constraint_type_flag = 0;
+    Map->constraint.region_flag = FALSE;
+    Map->constraint.type_flag = FALSE;
+    Map->constraint.field_flag = FALSE;
+}
+
+/*!
+   \brief Set constraint field
+
+   Vect_read_next_line() will read only features of given type. Note
+   that categories must be read otherwise this constraint is ignored.
 
+   Note: Field is called layer on user level.
+
+   \param Map vector map
+   \param field field number (-1 for all fields)
+
+   \return 0 on success
+   \return -1 invalid feature type
+*/
+int Vect_set_constraint_field(struct Map_info *Map, int field)
+{
+    if (field == -1) {
+	Map->constraint.field_flag = FALSE;
+	return 0;
+    }
+    if (field < 1) {
+	return -1;
+    }
+    Map->constraint.field = field;
+    Map->constraint.field_flag = TRUE;
+    
     return 0;
 }