[GRASS-SVN] r52139 - grass/branches/develbranch_6/lib/vector/neta

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 19 09:30:16 PDT 2012


Author: mmetz
Date: 2012-06-19 09:30:15 -0700 (Tue, 19 Jun 2012)
New Revision: 52139

Modified:
   grass/branches/develbranch_6/lib/vector/neta/utils.c
Log:
netalib: backport fixes from trunk

Modified: grass/branches/develbranch_6/lib/vector/neta/utils.c
===================================================================
--- grass/branches/develbranch_6/lib/vector/neta/utils.c	2012-06-19 16:29:39 UTC (rev 52138)
+++ grass/branches/develbranch_6/lib/vector/neta/utils.c	2012-06-19 16:30:15 UTC (rev 52139)
@@ -174,7 +174,7 @@
 	for (i = 1; i <= nnodes; i++)
 	    nodes_to_features[i] = -1;
 
-    for (i = 1; i <= nlines; i++)
+    for (i = 1; i <= nlines; i++) {
 	if (varray->c[i]) {
 	    int type = Vect_read_line(map, NULL, NULL, i);
 
@@ -196,6 +196,7 @@
 		    nodes_to_features[node1] = nodes_to_features[node2] = i;
 	    }
 	}
+    }
 }
 
 /*!
@@ -208,39 +209,58 @@
    \param cat ?
    \param[out] pointer to varray structure
 
-   \return ?
+   \return number of items set
+   \return -1 on error
  */
 int NetA_initialise_varray(struct Map_info *In, int layer, int mask_type,
 			   char *where, char *cat, struct varray **varray)
 {
+    int n, ni;
+    
+    if (layer < 1)
+	G_fatal_error(_("'%s' must be > 0"), "layer");
+
+    n = Vect_get_num_lines(In);
+    *varray = Vect_new_varray(n);
+    ni = 0;
+    
     /* parse filter option and select appropriate lines */
     if (where) {
-	if (layer < 1)
-	    G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", "where");
 	if (cat)
 	    G_warning(_("'where' and 'cats' parameters were supplied, cat will be ignored"));
-	*varray = Vect_new_varray(Vect_get_num_lines(In));
-	if (Vect_set_varray_from_db
-	    (In, layer, where, mask_type, 1, *varray) == -1) {
+	ni = Vect_set_varray_from_db(In, layer, where, mask_type, 1, *varray);
+	if (ni == -1) {
 	    G_warning(_("Unable to load data from database"));
-	    return 0;
 	}
-	return 1;
+	return ni;
     }
     else if (cat) {
-	if (layer < 1)
-	    G_fatal_error(_("'%s' must be > 0 for '%s'"), "layer", "cat");
-	*varray = Vect_new_varray(Vect_get_num_lines(In));
-	if (Vect_set_varray_from_cat_string
-	    (In, layer, cat, mask_type, 1, *varray) == -1) {
+	ni = Vect_set_varray_from_cat_string(In, layer, cat, mask_type, 1, *varray);
+	if (ni == -1) {
 	    G_warning(_("Problem loading category values"));
-	    return 0;
 	}
-	return 1;
+	return ni;
     }
-    else {
-	return 2;
-    }
+    else { /* all features of given layer */
+	int i, cat;
+	int ltype;			/* line type */
+	struct line_cats *Cats;
 
+	Cats = Vect_new_cats_struct();
 
+	for (i = 1; i <= n; i++) {
+	    ltype = Vect_read_line(In, NULL, Cats, i);
+
+	    if (!(ltype & mask_type))
+		continue;	/* is not specified type */
+
+	    if (Vect_cat_get(Cats, layer, &cat)) {
+		(*varray)->c[i] = 1;
+		ni++;
+	    }
+	}
+	Vect_destroy_cats_struct(Cats);
+
+	return ni;
+    }
 }



More information about the grass-commit mailing list