[GRASS-SVN] r56760 - grass/trunk/misc/m.cogo

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 17 04:07:53 PDT 2013


Author: hamish
Date: 2013-06-17 04:07:53 -0700 (Mon, 17 Jun 2013)
New Revision: 56760

Modified:
   grass/trunk/misc/m.cogo/m.cogo.html
   grass/trunk/misc/m.cogo/main.c
Log:
add flag to repeat the first coord, closing a boundary (wish #1725)
and increase precision to ensure a lossless round trip. (merge from devbr6)


Modified: grass/trunk/misc/m.cogo/m.cogo.html
===================================================================
--- grass/trunk/misc/m.cogo/m.cogo.html	2013-06-17 11:04:18 UTC (rev 56759)
+++ grass/trunk/misc/m.cogo/m.cogo.html	2013-06-17 11:07:53 UTC (rev 56760)
@@ -113,9 +113,9 @@
        v.in.ascii -n format=standard out=cogo_line
 </pre></div>
 
-Unclosed lines may be snapped with <em>v.clean</em>, converted to
-boundaries with <em>v.type</em>, and closed boundaries may be
-converted to areas with <em>v.centroids</em>.
+Lines may be closed by using the <b>-c</b> flag or snapped with
+<em>v.clean</em>, lines may be converted to boundaries with <em>v.type</em>,
+and closed boundaries may be converted to areas with <em>v.centroids</em>.
 
 
 <h2>SEE ALSO</h2>
@@ -129,7 +129,6 @@
 </em>
 
 
-
 <h2>AUTHOR</h2>
 
 Eric G. Miller

Modified: grass/trunk/misc/m.cogo/main.c
===================================================================
--- grass/trunk/misc/m.cogo/main.c	2013-06-17 11:04:18 UTC (rev 56759)
+++ grass/trunk/misc/m.cogo/main.c	2013-06-17 11:07:53 UTC (rev 56760)
@@ -49,29 +49,29 @@
 };
 
 
-static void print_coordinates(FILE * outfile, struct survey_record *in)
+static void print_coordinates(FILE *outfile, struct survey_record *in)
 {
     if (in->haslabel == YES)
-	fprintf(outfile, "%f %f %s\n", in->x, in->y, in->label);
+	fprintf(outfile, "%.15g %.15g %s\n", in->x, in->y, in->label);
     else
-	fprintf(outfile, "%f %f\n", in->x, in->y);
+	fprintf(outfile, "%.15g %.15g\n", in->x, in->y);
 }
 
 
-static void print_cogo(FILE * outfile, struct survey_record *in)
+static void print_cogo(FILE *outfile, struct survey_record *in)
 {
     if (in->haslabel == YES)
-	fprintf(outfile, "%s %s %d:%d:%.3f %s %f\n",
+	fprintf(outfile, "%s %s %02d:%02d:%02.9g %s %.13g\n",
 		in->label, in->n_s, in->deg, in->min, in->sec,
 		in->e_w, in->dist);
     else
-	fprintf(outfile, "%s %d:%d:%.3f %s %f\n",
+	fprintf(outfile, "%s %02d:%02d:%02.9g %s %.13g\n",
 		in->n_s, in->deg, in->min, in->sec, in->e_w, in->dist);
 
 }
 
 
-static const char *next_line(FILE * infile)
+static const char *next_line(FILE *infile)
 {
     static char line[512];
     const char *cptr;
@@ -210,12 +210,14 @@
     struct Flag *format;
     struct Flag *quiet;
     struct Flag *reverse;
+    struct Flag *close;
     struct GModule *module;
     FILE *infile, *outfile;
-    struct survey_record record;
+    struct survey_record record, first_record;
     const char *cptr;
     char *ss;
-    int verbose = 1, linenum = 0;
+    int verbose = TRUE;
+    unsigned long linenum = 0, dataline = 0;
     int (*parse_line) (const char *, struct survey_record *);
     void (*print_func) (FILE *, struct survey_record *);
 
@@ -241,6 +243,11 @@
     reverse->description =
 	_("Convert from coordinates to bearing and distance");
 
+    close = G_define_flag();
+    close->key = 'c';
+    close->description =
+	_("Repeat the starting coordinate at the end to close a loop");
+
     input = G_define_standard_option(G_OPT_F_INPUT);
     input->required = NO;
     input->answer = "-";
@@ -289,7 +296,7 @@
     }
 
     if (quiet->answer)
-	verbose = 0;
+	verbose = FALSE;
 
     if (reverse->answer) {
 	parse_line = parse_reverse;
@@ -325,9 +332,19 @@
 		G_warning(_("Input parse error on line %d"), linenum);
 	    continue;
 	}
+
+	dataline++;
+
+	if (dataline == 1)
+	    first_record = record;
+
 	print_func(outfile, &record);
     }
 
+    if (close->answer)
+	print_func(outfile, &first_record);
+
+
     if (infile != stdin)
 	fclose(infile);
     if (outfile != stdout)



More information about the grass-commit mailing list