[GRASS-SVN] r45451 - grass/branches/develbranch_6/vector/v.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 23 11:15:38 EST 2011


Author: neteler
Date: 2011-02-23 08:15:38 -0800 (Wed, 23 Feb 2011)
New Revision: 45451

Modified:
   grass/branches/develbranch_6/vector/v.out.ascii/b2a.c
   grass/branches/develbranch_6/vector/v.out.ascii/local_proto.h
   grass/branches/develbranch_6/vector/v.out.ascii/out.c
Log:
flag to show table header in point mode

Modified: grass/branches/develbranch_6/vector/v.out.ascii/b2a.c
===================================================================
--- grass/branches/develbranch_6/vector/v.out.ascii/b2a.c	2011-02-23 06:35:45 UTC (rev 45450)
+++ grass/branches/develbranch_6/vector/v.out.ascii/b2a.c	2011-02-23 16:15:38 UTC (rev 45451)
@@ -6,10 +6,10 @@
 
 static int srch(const void *pa, const void *pb);
 
-int bin_to_asc(FILE *ascii,
+int bin_to_asc(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;
     double *xptr, *yptr, *zptr, x, y;
@@ -18,6 +18,7 @@
     char *xstring = NULL, *ystring = NULL, *zstring = NULL;
     struct Cell_head window;
     struct ilist *fcats;
+    int count = 0;
 
     /* where */
     struct field_info *Fi;
@@ -170,6 +171,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]) ||

Modified: grass/branches/develbranch_6/vector/v.out.ascii/local_proto.h
===================================================================
--- grass/branches/develbranch_6/vector/v.out.ascii/local_proto.h	2011-02-23 06:35:45 UTC (rev 45450)
+++ grass/branches/develbranch_6/vector/v.out.ascii/local_proto.h	2011-02-23 16:15:38 UTC (rev 45451)
@@ -3,6 +3,6 @@
 
 /* b2a.c */
 int bin_to_asc(FILE *, FILE *, struct Map_info *, int ver, int format, int dp,
-	       char *, int, int, char *, char **);
+	       char *, int, int, char *, char **, int);
 /* head.c */
 int write_head(FILE * dascii, struct Map_info *Map);

Modified: grass/branches/develbranch_6/vector/v.out.ascii/out.c
===================================================================
--- grass/branches/develbranch_6/vector/v.out.ascii/out.c	2011-02-23 06:35:45 UTC (rev 45450)
+++ grass/branches/develbranch_6/vector/v.out.ascii/out.c	2011-02-23 16:15:38 UTC (rev 45451)
@@ -32,7 +32,7 @@
     FILE *ascii, *att;
     struct Option *input, *output, *format_opt, *dp_opt, *delim_opt,
 	*field_opt, *column_opt, *where_opt;
-    struct Flag *verf, *region_flag;
+    struct Flag *verf, *header, *region_flag;
     int format, dp, field;
     char *fs;
     struct Map_info Map;
@@ -90,6 +90,11 @@
     verf->key = 'o';
     verf->description = _("Create old (version 4) ASCII file");
 
+    header = G_define_flag();
+    header->key = 'c';
+    header->description = _("Include column names in output (points mode)");
+    header->guisection = _("Points");
+
     region_flag = G_define_flag();
     region_flag->key = 'r';
     region_flag->description =
@@ -183,7 +188,7 @@
 
     bin_to_asc(ascii, att, &Map, ver, format, dp, fs,
 	       region_flag->answer, field, where_opt->answer,
-	       column_opt->answers);
+	       column_opt->answers, header->answer);
     
     if (ascii != NULL)
 	fclose(ascii);



More information about the grass-commit mailing list