[GRASS-SVN] r58403 - in grass/trunk: include/defs lib/vector/Vlib

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Dec 6 14:32:26 PST 2013


Author: martinl
Date: 2013-12-06 14:32:26 -0800 (Fri, 06 Dec 2013)
New Revision: 58403

Modified:
   grass/trunk/include/defs/vector.h
   grass/trunk/lib/vector/Vlib/cindex.c
Log:
vlib: implement Vect_cidx_get_unique_cats_by_index()


Modified: grass/trunk/include/defs/vector.h
===================================================================
--- grass/trunk/include/defs/vector.h	2013-12-06 18:59:59 UTC (rev 58402)
+++ grass/trunk/include/defs/vector.h	2013-12-06 22:32:26 UTC (rev 58403)
@@ -152,6 +152,7 @@
 int Vect_cidx_get_type_count(const struct Map_info *, int, int);
 int Vect_cidx_get_cat_by_index(const struct Map_info *, int, int, int *, int *,
                                int *);
+int Vect_cidx_get_unique_cats_by_index(struct Map_info *, int, struct ilist *);
 int Vect_cidx_find_next(const struct Map_info *, int, int, int, int, int *, int *);
 void Vect_cidx_find_all(const struct Map_info *, int, int, int, struct ilist *);
 int Vect_cidx_dump(const struct Map_info *, FILE *);

Modified: grass/trunk/lib/vector/Vlib/cindex.c
===================================================================
--- grass/trunk/lib/vector/Vlib/cindex.c	2013-12-06 18:59:59 UTC (rev 58402)
+++ grass/trunk/lib/vector/Vlib/cindex.c	2013-12-06 22:32:26 UTC (rev 58403)
@@ -11,6 +11,7 @@
   (>=v2). Read the file COPYING that comes with GRASS for details.
   
   \author Radim Blazek
+  \author Some contribution by Martin Landa <landa.martin gmail.com>
 */
 
 #include <stdlib.h>
@@ -245,7 +246,7 @@
 }
 
 /*!
-  \brief Get number of categories for given layer and category index 
+  \brief Get category, feature type and id for given layer and category index 
   
   \param Map pointer to Map_info structure
   \param field_index layer index
@@ -274,6 +275,40 @@
 }
 
 /*!
+  \brief Get list of unique categories for given layer index
+
+  \param Map pointer to Map_info structure
+  \param field_index layer index
+  \param[out] list output list of cats
+  
+  \return 1 on success
+  \return 0 on error
+*/
+int Vect_cidx_get_unique_cats_by_index(struct Map_info *Map, int field_index, struct ilist *list)
+{
+    int c;
+    struct Cat_index *ci;
+
+    check_status(Map);
+    check_index(Map, field_index);
+
+    ci = &(Map->plus.cidx[field_index]);
+    
+    /* force sorting index -- really needed? */
+    dig_cidx_sort(&(Map->plus));
+
+    Vect_reset_list(list);
+    if (ci->n_cats > 0)
+        Vect_list_append(list, ci->cat[0][0]);
+    for (c = 1; c < ci->n_cats; c++) {
+        if (ci->cat[c][0] != ci->cat[c - 1][0])
+            Vect_list_append(list, ci->cat[c][0]);
+    }
+    
+    return list->n_values == ci->n_ucats ? 1 : 0;
+}
+
+/*!
   \brief Find next line/area id for given category, start_index and type_mask 
   
   \param Map pointer to Map_info structure



More information about the grass-commit mailing list