[GRASS-SVN] r48021 - grass/trunk/vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Sep 1 06:16:54 EDT 2011


Author: martinl
Date: 2011-09-01 03:16:54 -0700 (Thu, 01 Sep 2011)
New Revision: 48021

Modified:
   grass/trunk/vector/v.out.ascii/args.c
   grass/trunk/vector/v.out.ascii/local_proto.h
   grass/trunk/vector/v.out.ascii/main.c
Log:
v.out.ascii: option <cats> added to filter features based on categories


Modified: grass/trunk/vector/v.out.ascii/args.c
===================================================================
--- grass/trunk/vector/v.out.ascii/args.c	2011-09-01 10:15:20 UTC (rev 48020)
+++ grass/trunk/vector/v.out.ascii/args.c	2011-09-01 10:16:54 UTC (rev 48021)
@@ -9,10 +9,11 @@
 
 void parse_args(int argc, char **argv,
 		char **input, char**output, int *format, int *dp, char **delim,
-		char **field, char ***columns, char **where, int *region, int *old_format, int *header)
+		char **field, char ***columns, char **where, int *region,
+		int *old_format, int *header, struct cat_list **clist)
 {
     struct Option *input_opt, *output_opt, *format_opt, *dp_opt, *delim_opt,
-	*field_opt, *column_opt, *where_opt;
+	*field_opt, *column_opt, *where_opt, *cats_opt;
     struct Flag *old_flag, *header_flag, *region_flag;
     
     input_opt = G_define_standard_option(G_OPT_V_INPUT);
@@ -21,9 +22,9 @@
     field_opt->guisection = _("Selection");
     
     output_opt = G_define_standard_option(G_OPT_F_OUTPUT);
-    output_opt->description =
-	_("Path to resulting ASCII file ('-' for standard output) "
-	  "or ASCII vector name if '-o' is defined");
+    output_opt->label = _("Name for output ASCII file "
+			  "or ASCII vector name if '-o' is defined");
+    output_opt->description = _("'-' for standard output");
     output_opt->required = NO;
     output_opt->answer = "-";
 
@@ -31,6 +32,9 @@
     column_opt->description = _("Name of attribute column(s) to be exported (point mode)");
     column_opt->guisection = _("Points");
     
+    cats_opt = G_define_standard_option(G_OPT_V_CATS);
+    cats_opt->guisection = _("Selection");
+    
     where_opt = G_define_standard_option(G_OPT_DB_WHERE);
     where_opt->guisection = _("Selection");
 
@@ -113,6 +117,18 @@
     if (where_opt->answer) {
 	*where = G_store(where_opt->answer);
     }
+    *clist = NULL;
+    if (cats_opt->answer) {
+	int ret;
+	
+	*clist = Vect_new_cat_list();
+	(*clist)->field = atoi(field_opt->answer);
+	if ((*clist)->field < 1)
+	    G_fatal_error(_("Option <%s> must be > 0"), field_opt->key);
+	ret = Vect_str_to_cat_list(cats_opt->answer, *clist);
+	if (ret > 0)
+	    G_fatal_error(_("%d errors in cat option"), ret);
+    }
     *region = region_flag->answer ? 1 : 0;
     *old_format = old_flag->answer ? 1 : 0;
     *header = header_flag->answer ? 1 : 0;

Modified: grass/trunk/vector/v.out.ascii/local_proto.h
===================================================================
--- grass/trunk/vector/v.out.ascii/local_proto.h	2011-09-01 10:15:20 UTC (rev 48020)
+++ grass/trunk/vector/v.out.ascii/local_proto.h	2011-09-01 10:16:54 UTC (rev 48021)
@@ -1,4 +1,5 @@
 /* args.c */
 void parse_args(int, char **,
 		char **, char**, int *, int *, char **,
-		char **, char ***, char **, int *, int *, int *);
+		char **, char ***, char **, int *, int *, int *,
+		struct cat_list **);

Modified: grass/trunk/vector/v.out.ascii/main.c
===================================================================
--- grass/trunk/vector/v.out.ascii/main.c	2011-09-01 10:15:20 UTC (rev 48020)
+++ grass/trunk/vector/v.out.ascii/main.c	2011-09-01 10:16:54 UTC (rev 48021)
@@ -8,7 +8,7 @@
  *             Martin Landa, CTU in Prague, Czech Republic (v.out.ascii.db merged & update (OGR) for GRASS7)
  *
  * PURPOSE:    Writes GRASS vector data as ASCII files
- * COPYRIGHT:  (C) 2000-2009 by the GRASS Development Team
+ * COPYRIGHT:  (C) 2000-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
@@ -37,6 +37,8 @@
     int format, dp, field, ret, region, old_format, header;
     int ver, pnt;
 
+    struct cat_list *clist;
+    
     G_gisinit(argv[0]);
 
     module = G_define_module();
@@ -47,7 +49,8 @@
 	_("Exports a vector map to a GRASS ASCII vector representation.");
 
     parse_args(argc, argv, &input, &output, &format, &dp, &delim,
-	       &field_name, &columns, &where, &region, &old_format, &header);
+	       &field_name, &columns, &where, &region, &old_format, &header,
+	       &clist);
     
     if (format == GV_ASCII_FORMAT_STD && columns) {
 	G_warning(_("Parameter 'column' ignored in standard mode"));
@@ -116,11 +119,11 @@
 			  output);
     }
 
-    if (where || columns)
+    if (where || columns || clist)
 	G_message(_("Fetching data..."));
     ret = Vect_write_ascii(ascii, att, &Map, ver, format, dp, delim,
-			   region, field, where,
-			   columns, header);
+			   region, field, clist, (const char *)where,
+			   (const char **)columns, header);
 
     if (ret < 1) {
 	if (format == GV_ASCII_FORMAT_POINT) {



More information about the grass-commit mailing list