瀏覽代碼

add flag to repeat the first coord, closing a boundary (wish https://trac.osgeo.org/grass/ticket/1725)
and increase precision to ensure a lossless round trip. (merge from devbr6)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@56760 15284696-431f-4ddb-bdfa-cd5b030d7da7

Hamish Bowman 12 年之前
父節點
當前提交
7d43c4606a
共有 2 個文件被更改,包括 30 次插入14 次删除
  1. 3 4
      misc/m.cogo/m.cogo.html
  2. 27 10
      misc/m.cogo/main.c

+ 3 - 4
misc/m.cogo/m.cogo.html

@@ -113,9 +113,9 @@ Shell script to import as a vector line map:
        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 @@ converted to areas with <em>v.centroids</em>.
 </em>
 
 
-
 <h2>AUTHOR</h2>
 
 Eric G. Miller

+ 27 - 10
misc/m.cogo/main.c

@@ -49,29 +49,29 @@ struct survey_record
 };
 
 
-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 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
     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 @@ int main(int argc, char **argv)
     }
 
     if (quiet->answer)
-	verbose = 0;
+	verbose = FALSE;
 
     if (reverse->answer) {
 	parse_line = parse_reverse;
@@ -325,9 +332,19 @@ int main(int argc, char **argv)
 		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)