[GRASS-SVN] r39814 - in grass/trunk: include lib/vector/Vlib vector/v.clean

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Nov 26 16:35:58 EST 2009


Author: martinl
Date: 2009-11-26 16:35:58 -0500 (Thu, 26 Nov 2009)
New Revision: 39814

Modified:
   grass/trunk/include/vector.h
   grass/trunk/lib/vector/Vlib/cats.c
   grass/trunk/lib/vector/Vlib/map.c
   grass/trunk/vector/v.clean/main.c
Log:
v.clean: OGR support (read access)
vlib: Vect_copy_map_lines_field() added


Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h	2009-11-26 20:52:44 UTC (rev 39813)
+++ grass/trunk/include/vector.h	2009-11-26 21:35:58 UTC (rev 39814)
@@ -385,6 +385,7 @@
 			    int);
 int Vect_option_to_types(const struct Option *);
 int Vect_copy_map_lines(struct Map_info *, struct Map_info *);
+int Vect_copy_map_lines_field(struct Map_info *, int, struct Map_info *);
 int Vect_copy(const char *, const char *, const char *);
 int Vect_rename(const char *, const char *);
 int Vect_copy_table(const struct Map_info *, struct Map_info *, int, int,

Modified: grass/trunk/lib/vector/Vlib/cats.c
===================================================================
--- grass/trunk/lib/vector/Vlib/cats.c	2009-11-26 20:52:44 UTC (rev 39813)
+++ grass/trunk/lib/vector/Vlib/cats.c	2009-11-26 21:35:58 UTC (rev 39814)
@@ -146,33 +146,35 @@
 
    \param Cats line_cats structure
    \param field layer number
-   \param[out] cat pointer to variable where cat will be written
+   \param[out] cat pointer to variable where cat will be written (can be NULL)
 
    \return 1 found
    \return 0 layer does not exist
  */
 int Vect_cat_get(const struct line_cats *Cats, int field, int *cat)
 {
-    register int n;
+    int n;
 
     /* check input value */
     /*
        if (field < 1 || field > GV_FIELD_MAX)
        return (0);
      */
+    
+    if (cat)
+	*cat = -1;
 
-    *cat = -1;
-
     /* go through cats and find if field exist */
     for (n = 0; n < Cats->n_cats; n++) {
 	if (Cats->field[n] == field) {
-	    *cat = Cats->cat[n];
-	    return (1);
+	    if (cat)
+		*cat = Cats->cat[n];
+	    return 1;
 	}
     }
 
     /* field was not found */
-    return (0);
+    return 0;
 }
 
 /*!

Modified: grass/trunk/lib/vector/Vlib/map.c
===================================================================
--- grass/trunk/lib/vector/Vlib/map.c	2009-11-26 20:52:44 UTC (rev 39813)
+++ grass/trunk/lib/vector/Vlib/map.c	2009-11-26 21:35:58 UTC (rev 39814)
@@ -31,7 +31,8 @@
 #include <grass/glocale.h>
 
 /*!
-   \brief Copy all alive elements of opened vector map to another opened vector map
+   \brief Copy all alive vector features of opened vector map to
+   another opened vector map
 
    \param In input vector map
    \param[out] Out output vector map
@@ -41,6 +42,22 @@
  */
 int Vect_copy_map_lines(struct Map_info *In, struct Map_info *Out)
 {
+    return Vect_copy_map_lines_field(In, -1, Out);
+}
+
+/*!
+   \brief Copy all alive vector features from given layer of opened
+   vector map to another opened vector map
+
+   \param In input vector map
+   \param field layer number (-1 for all layers)
+   \param[out] Out output vector map
+
+   \return 0 on success
+   \return 1 on error
+ */
+int Vect_copy_map_lines_field(struct Map_info *In, int field, struct Map_info *Out)
+{
     int i, type, nlines, ret;
     struct line_pnts *Points;
     struct line_cats *Cats;
@@ -70,7 +87,10 @@
 	    }
 	    if (type == 0)
 		continue;	/* dead line */
-
+	    
+	    if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
+		continue;       /* different layer */
+	    
 	    Vect_write_line(Out, type, Points, Cats);
 	}
     }
@@ -90,6 +110,10 @@
 	    else if (type == 0) {	/* dead line */
 		continue;
 	    }
+	    
+	    if (field != -1 && Vect_cat_get(Cats, field, NULL) == 0)
+		continue;       /* different layer */
+	    
 	    Vect_write_line(Out, type, Points, Cats);
 	}
     }
@@ -153,8 +177,7 @@
    \return -1 error
    \return 0 success
  */
-int
-Vect_copy(const char *in, const char *mapset, const char *out)
+int Vect_copy(const char *in, const char *mapset, const char *out)
 {
     int i, n, ret, type;
     struct Map_info In, Out;

Modified: grass/trunk/vector/v.clean/main.c
===================================================================
--- grass/trunk/vector/v.clean/main.c	2009-11-26 20:52:44 UTC (rev 39813)
+++ grass/trunk/vector/v.clean/main.c	2009-11-26 21:35:58 UTC (rev 39814)
@@ -3,10 +3,11 @@
  * * MODULE:       v.clean
  * * 
  * * AUTHOR(S):    Radim Blazek
+ * *               OGR support by Martin Landa <landa.martin gmail.com> (2009)
+ * *
+ * * PURPOSE:      Clean vector features
  * *               
- * * PURPOSE:      Clean lines
- * *               
- * * COPYRIGHT:    (C) 2001 by the GRASS Development Team
+ * * COPYRIGHT:    (C) 2001-2009 by the GRASS Development Team
  * *
  * *               This program is free software under the 
  * *               GNU General Public License (>=v2). 
@@ -17,9 +18,11 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdio.h>
+
 #include <grass/gis.h>
 #include <grass/vector.h>
 #include <grass/glocale.h>
+
 #include "proto.h"
 
 int main(int argc, char *argv[])
@@ -27,7 +30,7 @@
     struct Map_info In, Out, Err, *pErr;
     int i, otype, with_z;
     struct GModule *module;
-    struct Option *in_opt, *out_opt, *type_opt, *tool_opt, *thresh_opt,
+    struct Option *in_opt, *field_opt, *out_opt, *type_opt, *tool_opt, *thresh_opt,
 	*err_opt;
     struct Flag *no_build_flag;
     int *tools, ntools, atools;
@@ -44,9 +47,12 @@
     module->description = _("Toolset for cleaning topology of vector map.");
 
     in_opt = G_define_standard_option(G_OPT_V_INPUT);
+    field_opt = G_define_standard_option(G_OPT_V_FIELD);
+    field_opt->guisection = _("Selection");
+    type_opt = G_define_standard_option(G_OPT_V3_TYPE);
+    type_opt->guisection = _("Selection");
+
     out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
-    type_opt = G_define_standard_option(G_OPT_V_TYPE);
-    type_opt->options = "point,line,boundary,centroid,area,face,kernel";
 
     err_opt = G_define_standard_option(G_OPT_V_OUTPUT);
     err_opt->key = "error";
@@ -89,10 +95,8 @@
     thresh_opt->type = TYPE_DOUBLE;
     thresh_opt->required = NO;
     thresh_opt->multiple = YES;
-    thresh_opt->label = "Threshold";
-    thresh_opt->description =
-	_("Threshold in map units, one value for each tool "
-	  "(default: 0.0[,0.0,...])");
+    thresh_opt->label = _("Threshold in map units, one value for each tool");
+    thresh_opt->description = _("Default: 0.0[,0.0,...])");
 
     no_build_flag = G_define_flag();
     no_build_flag->key = 'b';
@@ -240,7 +244,7 @@
      * virtual centroids (shapefile/OGR) and level 1 is better if input is too big 
      * and build in previous module (like v.in.ogr or other call to v.clean) would take 
      * a long time */
-    level = Vect_open_old(&In, in_opt->answer, "");
+    level = Vect_open_old2(&In, in_opt->answer, "", field_opt->answer);
 
     with_z = Vect_is_3d(&In);
 
@@ -265,13 +269,13 @@
     }
 
     /* Copy input to output */
-    G_message(_("Copying vector lines..."));
+    G_message(_("Copying vector features..."));
     Vect_copy_head_data(&In, &Out);
     Vect_hist_copy(&In, &Out);
     Vect_hist_command(&Out);
 
     /* This works for both level 1 and 2 */
-    Vect_copy_map_lines(&In, &Out);
+    Vect_copy_map_lines_field(&In, Vect_get_field_number(&In, field_opt->answer), &Out);
     if (Vect_copy_tables(&In, &Out, 0))
         G_warning(_("Failed to copy attribute table to output map"));
 



More information about the grass-commit mailing list