فهرست منبع

vlib: Vect_field_cat_get() added
v.out.ascii: fix trac https://trac.osgeo.org/grass/ticket/495
(merge from trunk, https://trac.osgeo.org/grass/changeset/35918)


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

Martin Landa 16 سال پیش
والد
کامیت
34ab9abc21
3فایلهای تغییر یافته به همراه47 افزوده شده و 10 حذف شده
  1. 1 0
      include/Vect.h
  2. 36 5
      lib/vector/Vlib/cats.c
  3. 10 5
      vector/v.out.ascii/b2a.c

+ 1 - 0
include/Vect.h

@@ -58,6 +58,7 @@ int Vect_cat_set(struct line_cats *, int, int);
 int Vect_cat_get(struct line_cats *, int, int *);
 int Vect_cat_get(struct line_cats *, int, int *);
 int Vect_cat_del(struct line_cats *, int);
 int Vect_cat_del(struct line_cats *, int);
 int Vect_field_cat_del(struct line_cats *, int, int);
 int Vect_field_cat_del(struct line_cats *, int, int);
+int Vect_field_cat_get(struct line_cats *, int, struct ilist *);
 int Vect_cat_in_array(int, int *, int);
 int Vect_cat_in_array(int, int *, int);
 int Vect_reset_cats(struct line_cats *);
 int Vect_reset_cats(struct line_cats *);
 int Vect_destroy_cats_struct(struct line_cats *);
 int Vect_destroy_cats_struct(struct line_cats *);

+ 36 - 5
lib/vector/Vlib/cats.c

@@ -5,7 +5,7 @@
  *
  *
  * Higher level functions for reading/writing/manipulating vectors.
  * Higher level functions for reading/writing/manipulating vectors.
  *
  *
- * (C) 2001-2008 by the GRASS Development Team
+ * (C) 2001-2009 by the GRASS Development Team
  *
  *
  * This program is free software under the 
  * This program is free software under the 
  * GNU General Public License (>=v2). 
  * GNU General Public License (>=v2). 
@@ -13,9 +13,9 @@
  * for details.
  * for details.
  *
  *
  * \author Original author CERL, probably Dave Gerdes or Mike
  * \author Original author CERL, probably Dave Gerdes or Mike
- * Higgins. Update to GRASS 5.7 Radim Blazek and David D. Gray.
- *
- * \date 2001-2008
+ * Higgins
+ * \author Update to GRASS 5.7 Radim Blazek and David D. Gray.
+ * \author Various updates by Martin Landa <landa.martin gmail.com>
  */
  */
 
 
 #include <stdlib.h>
 #include <stdlib.h>
@@ -48,7 +48,7 @@ struct line_cats *Vect_new_cats_struct()
 }
 }
 
 
 /*!
 /*!
-   \brief Creates and initializes line_cats structure.
+   \brief Creates and initializes line_cats structure (lower level fn)
 
 
    This structure is used for reading and writing vector cats. The
    This structure is used for reading and writing vector cats. The
    library routines handle all memory allocation.
    library routines handle all memory allocation.
@@ -179,6 +179,37 @@ int Vect_cat_get(struct line_cats *Cats, int field, int *cat)
 }
 }
 
 
 /*!
 /*!
+   \brief Get list of categories of given field.
+
+   \param Cats line_cats structure
+   \param field layer number
+   \param[out] cats pointer to list where cats will be written
+
+   \return number of found categories
+   \return -1 on invalid field
+ */
+int Vect_field_cat_get(struct line_cats *Cats, int field, struct ilist *cats)
+{
+    int n;
+    
+    /* reset list of categories */
+    Vect_reset_list(cats);
+
+    /* check input value */
+    if (field < 1 || field > GV_FIELD_MAX)
+	return -1;
+    
+    /* go through cats and find if field exist */
+    for (n = 0; n < Cats->n_cats; n++) {
+	if (Cats->field[n] != field)
+	    continue;
+	Vect_list_append(cats, Cats->cat[n]);
+    }
+
+    return cats->n_values;
+}
+
+/*!
    \brief Delete all categories of given layer
    \brief Delete all categories of given layer
 
 
    \param[in] Cats line_cats structure
    \param[in] Cats line_cats structure

+ 10 - 5
vector/v.out.ascii/b2a.c

@@ -17,6 +17,7 @@ int bin_to_asc(FILE *ascii,
     struct line_cats *Cats;
     struct line_cats *Cats;
     char *xstring = NULL, *ystring = NULL, *zstring = NULL;
     char *xstring = NULL, *ystring = NULL, *zstring = NULL;
     struct Cell_head window;
     struct Cell_head window;
+    struct ilist *fcats;
 
 
     /* where */
     /* where */
     struct field_info *Fi;
     struct field_info *Fi;
@@ -61,6 +62,7 @@ int bin_to_asc(FILE *ascii,
     
     
     Points = Vect_new_line_struct();	/* init line_pnts struct */
     Points = Vect_new_line_struct();	/* init line_pnts struct */
     Cats = Vect_new_cats_struct();
     Cats = Vect_new_cats_struct();
+    fcats = Vect_new_list();
 
 
     proj = Vect_get_proj(Map);
     proj = Vect_get_proj(Map);
 
 
@@ -182,17 +184,20 @@ int bin_to_asc(FILE *ascii,
 	    else {
 	    else {
 		fprintf(ascii, "%s%s%s", xstring, fs, ystring);
 		fprintf(ascii, "%s%s%s", xstring, fs, ystring);
 	    }
 	    }
-	    if (Cats->n_cats > 0) {
-		if (Cats->n_cats > 1) {
+
+	    Vect_field_cat_get(Cats, field, fcats);
+	    
+	    if (fcats->n_values > 0) {
+		if (fcats->n_values > 1) {
 		    G_warning(_("Feature has more categories. Only first category (%d) "
 		    G_warning(_("Feature has more categories. Only first category (%d) "
-				"is exported."), Cats->cat[0]);
+				"is exported."), fcats->value[0]);
 		}
 		}
-		fprintf(ascii, "%s%d", fs, Cats->cat[0]);
+		fprintf(ascii, "%s%d", fs, fcats->value[0]);
 		
 		
 		/* print attributes */
 		/* print attributes */
 		if (columns) {
 		if (columns) {
 		    for(i = 0; columns[i]; i++) {
 		    for(i = 0; columns[i]; i++) {
-			if (db_select_value(driver, Fi->table, Fi->key, Cats->cat[0],
+			if (db_select_value(driver, Fi->table, Fi->key, fcats->value[0],
 					    columns[i], &value) < 0)
 					    columns[i], &value) < 0)
 			    G_fatal_error(_("Unable to select record from table <%s> (key %s, column %s)"),
 			    G_fatal_error(_("Unable to select record from table <%s> (key %s, column %s)"),
 					  Fi->table, Fi->key, columns[i]);
 					  Fi->table, Fi->key, columns[i]);