[GRASS-SVN] r45454 - in grass/trunk: include lib/vector/Vlib vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 23 11:48:46 EST 2011


Author: neteler
Date: 2011-02-23 08:48:46 -0800 (Wed, 23 Feb 2011)
New Revision: 45454

Modified:
   grass/trunk/include/vector.h
   grass/trunk/lib/vector/Vlib/ascii.c
   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:
flag to show table header in point mode

Modified: grass/trunk/include/vector.h
===================================================================
--- grass/trunk/include/vector.h	2011-02-23 16:33:55 UTC (rev 45453)
+++ grass/trunk/include/vector.h	2011-02-23 16:48:46 UTC (rev 45454)
@@ -425,7 +425,7 @@
 int Vect_read_ascii_head(FILE *, struct Map_info *);
 int Vect_write_ascii(FILE *, FILE *, struct Map_info *, int,
 		     int, int, char *, int,
-		     int, char*, char **);
+		     int, char*, char **, int);
 void Vect_write_ascii_head(FILE *, struct Map_info *);
 
 /* Simple Features */

Modified: grass/trunk/lib/vector/Vlib/ascii.c
===================================================================
--- grass/trunk/lib/vector/Vlib/ascii.c	2011-02-23 16:33:55 UTC (rev 45453)
+++ grass/trunk/lib/vector/Vlib/ascii.c	2011-02-23 16:48:46 UTC (rev 45454)
@@ -284,7 +284,7 @@
 int Vect_write_ascii(FILE *ascii,
 		     FILE *att, struct Map_info *Map, int ver,
 		     int format, int dp, char *fs, int region_flag,
-		     int field, char* where, char **columns)
+		     int field, char* where, char **columns, int header)
 {
     int type, ctype, i, cat, proj, n_lines;
     double *xptr, *yptr, *zptr, x, y;
@@ -293,6 +293,7 @@
     char *xstring = NULL, *ystring = NULL, *zstring = NULL;
     struct Cell_head window;
     struct ilist *fcats;
+    int count = 0;
 
     /* where */
     struct field_info *Fi;
@@ -444,6 +445,32 @@
 	    G_asprintf(&ystring, "%.*f", dp, Points->y[0]);
 	    G_trim_decimal(ystring);
 
+	    Vect_field_cat_get(Cats, field, fcats);
+
+	    /* print header */
+	    if (header && count < 1) {
+		count++;
+		if (Map->head.with_z)
+		    fprintf(ascii, "east%snorth%sheight%scat", fs, fs, fs);
+		else
+		    fprintf(ascii, "east%snorth%scat", fs, fs);
+		if (columns) {
+		    for (i = 0; columns[i]; i++) {
+			if (db_select_value
+			    (driver, Fi->table, Fi->key, fcats->value[0],
+			     columns[i], &value) < 0)
+			    G_fatal_error(_("Unable to select record from table <%s> (key %s, column %s)"),
+					  Fi->table, Fi->key, columns[i]);
+			if (columns[i])
+			    fprintf(ascii, "%s%s", fs, columns[i]);
+			else
+			    fprintf(ascii, "%s", columns[i]);
+		    }
+		}
+		fprintf(ascii, "\n");
+
+	    }
+
 	    if (Map->head.with_z && ver == 5) {
 		if (region_flag) {
 		    if ((window.top < Points->z[0]) ||
@@ -459,7 +486,6 @@
 		fprintf(ascii, "%s%s%s", xstring, fs, ystring);
 	    }
 
-	    Vect_field_cat_get(Cats, field, fcats);
 	    
 	    if (fcats->n_values > 0) {
 		if (fcats->n_values > 1) {

Modified: grass/trunk/vector/v.out.ascii/args.c
===================================================================
--- grass/trunk/vector/v.out.ascii/args.c	2011-02-23 16:33:55 UTC (rev 45453)
+++ grass/trunk/vector/v.out.ascii/args.c	2011-02-23 16:48:46 UTC (rev 45454)
@@ -9,11 +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)
+		char **field, char ***columns, char **where, int *region, int *old_format, int *header)
 {
     struct Option *input_opt, *output_opt, *format_opt, *dp_opt, *delim_opt,
 	*field_opt, *column_opt, *where_opt;
-    struct Flag *old_flag, *region_flag;
+    struct Flag *old_flag, *header_flag, *region_flag;
     
     input_opt = G_define_standard_option(G_OPT_V_INPUT);
 
@@ -61,6 +61,11 @@
     old_flag->key = 'o';
     old_flag->description = _("Create old (version 4) ASCII file");
 
+    header_flag = G_define_flag();
+    header_flag->key = 'c';
+    header_flag->description = _("Include column names in output (points mode)");
+    header_flag->guisection = _("Points");
+
     region_flag = G_define_flag();
     region_flag->key = 'r';
     region_flag->description =
@@ -110,4 +115,5 @@
     }
     *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-02-23 16:33:55 UTC (rev 45453)
+++ grass/trunk/vector/v.out.ascii/local_proto.h	2011-02-23 16:48:46 UTC (rev 45454)
@@ -1,4 +1,4 @@
 /* args.c */
 void parse_args(int, char **,
 		char **, char**, int *, int *, char **,
-		char **, char ***, char **, int *, int *);
+		char **, char ***, char **, int *, int *, int *);

Modified: grass/trunk/vector/v.out.ascii/main.c
===================================================================
--- grass/trunk/vector/v.out.ascii/main.c	2011-02-23 16:33:55 UTC (rev 45453)
+++ grass/trunk/vector/v.out.ascii/main.c	2011-02-23 16:48:46 UTC (rev 45454)
@@ -34,7 +34,7 @@
 
     FILE *ascii, *att;
     char *input, *output, *delim, **columns, *where, *field_name;
-    int format, dp, field, ret, region, old_format;
+    int format, dp, field, ret, region, old_format, header;
     int ver, pnt;
 
     G_gisinit(argv[0]);
@@ -47,7 +47,7 @@
 	_("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);
+	       &field_name, &columns, &where, &region, &old_format, &header);
     
     if (format == GV_ASCII_FORMAT_STD && columns) {
 	G_warning(_("Parameter 'column' ignored in standard mode"));
@@ -120,7 +120,7 @@
 	G_message(_("Fetching data..."));
     ret = Vect_write_ascii(ascii, att, &Map, ver, format, dp, delim,
 			   region, field, where,
-			   columns);
+			   columns, header);
 
     if (ret < 1) {
 	if (format == GV_ASCII_FORMAT_POINT) {



More information about the grass-commit mailing list