[GRASS-SVN] r37979 - in grass/branches/develbranch_6: display/d.profile general/g.region lib/gis raster/r.distance raster/r.out.ascii raster/r.stats sites/s.out.ascii

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jun 19 21:11:11 EDT 2009


Author: hamish
Date: 2009-06-19 21:11:11 -0400 (Fri, 19 Jun 2009)
New Revision: 37979

Modified:
   grass/branches/develbranch_6/display/d.profile/DumpProfile.c
   grass/branches/develbranch_6/display/d.profile/PlotProfile.c
   grass/branches/develbranch_6/display/d.profile/What.c
   grass/branches/develbranch_6/general/g.region/printwindow.c
   grass/branches/develbranch_6/lib/gis/wind_format.c
   grass/branches/develbranch_6/raster/r.distance/report.c
   grass/branches/develbranch_6/raster/r.out.ascii/formspecific.c
   grass/branches/develbranch_6/raster/r.stats/raw_stats.c
   grass/branches/develbranch_6/sites/s.out.ascii/main.c
Log:
output correct precision for different projection types (bugs #654 and #335)

Modified: grass/branches/develbranch_6/display/d.profile/DumpProfile.c
===================================================================
--- grass/branches/develbranch_6/display/d.profile/DumpProfile.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/display/d.profile/DumpProfile.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -17,6 +17,7 @@
     char *buf2 = G_calloc(UCAT_STR_SIZE, sizeof(char));
     char *outfile = G_calloc(strlen(fname) + 3, sizeof(char));
     char coords[4][80];
+    char outfmt[24];
     FILE *outFile;
     struct ProfileNode *ptr;
 
@@ -55,10 +56,15 @@
 	    _fmt_ucat(&profile->MaxCat, &profile->MinCat, buf2));
     fprintf(outFile, "# dist value east north\n");
 
+
+    if (G_projection() == PROJECTION_LL)
+	strcpy(outfmt, "%f %s %.8f %.8f\n");
+    else
+	strcpy(outfmt, "%f %s %.3f %.3f\n");
+
     /* Now loop through the nodes, one value per line */
     for (ptr = profile->ptr; ptr != NULL; ptr = ptr->next) {
-	fprintf(outFile, "%f %s %f %f\n",
-		ptr->dist,
+	fprintf(outFile, outfmt, ptr->dist,
 		_fmt_ucat(&ptr->cat, &profile->MinCat, buf),
 		ptr->east, ptr->north);
     }

Modified: grass/branches/develbranch_6/display/d.profile/PlotProfile.c
===================================================================
--- grass/branches/develbranch_6/display/d.profile/PlotProfile.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/display/d.profile/PlotProfile.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -98,8 +98,14 @@
     text_height = TEXT_HEIGHT * (b - t);
     text_width = text_height * 0.8;
     R_standard_color(D_translate_color(DEFAULT_FG_COLOR));
-    sprintf(txt_buf, "%s: From (%10.2f,%10.2f) to (%10.2f,%10.2f)",
+
+    if (G_projection() == PROJECTION_LL)
+	sprintf(txt_buf, "%s: From (%10.6f,%10.6f) to (%10.6f,%10.6f)",
 	    letter, profile.e1, profile.n1, profile.e2, profile.n2);
+    else
+	sprintf(txt_buf, "%s: From (%10.2f,%10.2f) to (%10.2f,%10.2f)",
+	    letter, profile.e1, profile.n1, profile.e2, profile.n2);
+
     done = 0;
     do {
 	R_get_text_box(txt_buf, &tt, &tb, &tl, &tr);

Modified: grass/branches/develbranch_6/display/d.profile/What.c
===================================================================
--- grass/branches/develbranch_6/display/d.profile/What.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/display/d.profile/What.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -35,10 +35,19 @@
 	sprintf(txt_buf, "%s in mapset %s", name, mapset);
 	DrawText(22, 1, 1, txt_buf);
 	R_standard_color(D_translate_color(DEFAULT_FG_COLOR));
-	sprintf(txt_buf, "EAST: %10.2f", east);
+
+	if (G_projection() == PROJECTION_LL)
+	    sprintf(txt_buf, "EAST: %10.6f", east);
+	else
+	    sprintf(txt_buf, "EAST: %10.2f", east);
 	DrawText(22, 2, 1, txt_buf);
-	sprintf(txt_buf, "NORTH: %10.2f", north);
+
+	if (G_projection() == PROJECTION_LL)
+	    sprintf(txt_buf, "NORTH: %10.6f", north);
+	else
+	    sprintf(txt_buf, "NORTH: %10.2f", north);
 	DrawText(22, 3, 1, txt_buf);
+
 	if (NoCatStrings)
 	    sprintf(txt_buf, "(%d)", buf[col]);
 	else

Modified: grass/branches/develbranch_6/general/g.region/printwindow.c
===================================================================
--- grass/branches/develbranch_6/general/g.region/printwindow.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/general/g.region/printwindow.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -23,7 +23,7 @@
     double longitude, latitude;
 
     if (print_flag & PRINT_SH)
-	x = -1;
+	x = G_projection() == PROJECTION_LL ? -1 : 0;
     else
 	x = window->proj;
 

Modified: grass/branches/develbranch_6/lib/gis/wind_format.c
===================================================================
--- grass/branches/develbranch_6/lib/gis/wind_format.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/lib/gis/wind_format.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -18,7 +18,7 @@
 #include <grass/gis.h>
 
 
-static int format_double(double, char *);
+static void format_double(double, char *, int);
 
 
 /**
@@ -29,7 +29,7 @@
  *
  * \param[in] north northing
  * \param[in,out] buf buffer to hold formatted string
- * \param[in] projection
+ * \param[in] projection, or -1 to force full precision FP
  * \return always returns 0
  */
 
@@ -37,8 +37,10 @@
 {
     if (projection == PROJECTION_LL)
 	G_lat_format(north, buf);
+    else if (projection == -1)
+	format_double(north, buf, TRUE);
     else
-	format_double(north, buf);
+	format_double(north, buf, FALSE);
 
     return 0;
 }
@@ -52,7 +54,7 @@
  *
  * \param[in] east easting
  * \param[in,out] buf buffer to hold formatted string
- * \param[in] projection
+ * \param[in] projection, or -1 to force full precision FP
  * \return always returns 0
  */
 
@@ -60,8 +62,10 @@
 {
     if (projection == PROJECTION_LL)
 	G_lon_format(east, buf);
+    else if (projection == -1)
+	format_double(east, buf, TRUE);
     else
-	format_double(east, buf);
+	format_double(east, buf, FALSE);
 
     return 0;
 }
@@ -75,7 +79,7 @@
  *
  *  \param[in] resolution
  *  \param[in,out] buf buffer to hold formatted string
- *  \param[in] projection
+ *  \param[in] projection, or -1 to force full precision FP
  *  \return always returns 0
  */
 
@@ -83,23 +87,28 @@
 {
     if (projection == PROJECTION_LL)
 	G_llres_format(res, buf);
+    else if (projection == -1)
+	format_double(res, buf, TRUE);
     else
-	format_double(res, buf);
+	format_double(res, buf, FALSE);
 
     return 0;
 }
 
-static int format_double(double value, char *buf)
+/*
+ * 'full_prec' is boolean, FALSE uses %.8f,  TRUE uses %.15g
+ * The reason to have this is that for lat/lon "%.8f" is not
+ * enough to preserve fidelity once converted back into D:M:S,
+ * which leads to rounding errors, especially for resolution.
+ */
+static void format_double(double value, char *buf, int full_prec)
 {
-    /* if the programmer has lied to G_format_resolution() about the
-        projection type in order to get FP values for lat/lon coords,
-        "%.8f" is not enough to preserve fidelity once converted
-        back into D:M:S, which leads to rounding errors. */
-    if (G_projection() == PROJECTION_LL)
+    if (full_prec)
 	sprintf(buf, "%.15g", value);
     else
 	sprintf(buf, "%.8f", value);
+
     G_trim_decimal(buf);
 
-    return 0;
+    return;
 }

Modified: grass/branches/develbranch_6/raster/r.distance/report.c
===================================================================
--- grass/branches/develbranch_6/raster/r.distance/report.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/raster/r.distance/report.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -59,13 +59,17 @@
 	    fprintf(stdout, "%s%s", fs, temp);
 
 	    /* print coordinates of the closest pair */
-	    G_format_easting(east1, temp, -1);
+	    G_format_easting(east1, temp,
+			     G_projection() == PROJECTION_LL ? -1 : 0);
 	    fprintf(stdout, "%s%s", fs, temp);
-	    G_format_northing(north1, temp, -1);
+	    G_format_northing(north1, temp,
+			      G_projection() == PROJECTION_LL ? -1 : 0);
 	    fprintf(stdout, "%s%s", fs, temp);
-	    G_format_easting(east2, temp, -1);
+	    G_format_easting(east2, temp,
+			     G_projection() == PROJECTION_LL ? -1 : 0);
 	    fprintf(stdout, "%s%s", fs, temp);
-	    G_format_northing(north2, temp, -1);
+	    G_format_northing(north2, temp,
+			      G_projection() == PROJECTION_LL ? -1 : 0);
 	    fprintf(stdout, "%s%s", fs, temp);
 
 	    /* print category labels */

Modified: grass/branches/develbranch_6/raster/r.out.ascii/formspecific.c
===================================================================
--- grass/branches/develbranch_6/raster/r.out.ascii/formspecific.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/raster/r.out.ascii/formspecific.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -142,12 +142,16 @@
     fprintf(fp, "%d %d\n", region.cols, region.rows);
 
     /* Projection set to -1 to force floating point output */
-    G_format_easting(region.west + region.ew_res / 2., fromc, -1);
-    G_format_easting(region.east - region.ew_res / 2., toc, -1);
+    G_format_easting(region.west + region.ew_res / 2., fromc,
+		     G_projection() == PROJECTION_LL ? -1 : 0);
+    G_format_easting(region.east - region.ew_res / 2., toc,
+		     G_projection() == PROJECTION_LL ? -1 : 0);
     fprintf(fp, "%s %s\n", fromc, toc);
 
-    G_format_northing(region.south + region.ns_res / 2., fromc, -1);
-    G_format_northing(region.north - region.ns_res / 2., toc, -1);
+    G_format_northing(region.south + region.ns_res / 2., fromc,
+		      G_projection() == PROJECTION_LL ? -1 : 0);
+    G_format_northing(region.north - region.ns_res / 2., toc,
+		      G_projection() == PROJECTION_LL ? -1 : 0);
     fprintf(fp, "%s %s\n", fromc, toc);
 
     G_get_fp_range_min_max(&range, &Z_MIN, &Z_MAX);

Modified: grass/branches/develbranch_6/raster/r.stats/raw_stats.c
===================================================================
--- grass/branches/develbranch_6/raster/r.stats/raw_stats.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/raster/r.stats/raw_stats.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -44,7 +44,8 @@
 	}
 
 	if (with_coordinates)
-	    G_format_northing(G_row_to_northing(row + .5, &window), nbuf, -1);
+	    G_format_northing(G_row_to_northing(row + .5, &window), nbuf, 
+			      G_projection() == PROJECTION_LL ? -1 : 0);
 
 	for (col = 0; col < ncols; col++) {
 	    if (no_nulls || no_nulls_all) {
@@ -69,7 +70,7 @@
 	    }
 	    if (with_coordinates) {
 		G_format_easting(G_col_to_easting(col + .5, &window), ebuf,
-				 -1);
+				 G_projection() == PROJECTION_LL ? -1 : 0);
 		fprintf(stdout, "%s%s%s%s", ebuf, fs, nbuf, fs);
 	    }
 	    if (with_xy)

Modified: grass/branches/develbranch_6/sites/s.out.ascii/main.c
===================================================================
--- grass/branches/develbranch_6/sites/s.out.ascii/main.c	2009-06-19 22:17:11 UTC (rev 37978)
+++ grass/branches/develbranch_6/sites/s.out.ascii/main.c	2009-06-20 01:11:11 UTC (rev 37979)
@@ -115,9 +115,12 @@
     while (G_site_get(fd, site) == 0) {
 	if (all || G_site_in_region(site, &window)) {
 	    if (!full) {
-		G_format_easting(site->east, ebuf, -1);
-		G_format_northing(site->north, nbuf, -1);
+		G_format_easting(site->east, ebuf,
+				 G_projection() == PROJECTION_LL ? -1 : 0);
+		G_format_northing(site->north, nbuf,
+				  G_projection() == PROJECTION_LL ? -1 : 0);
 		fprintf(stdout, "%s%s%s", ebuf, fs, nbuf);
+
 		for (n = 0; n < site->dim_alloc; ++n) {
 		    sprintf(nbuf, "%.8f", site->dim[n]);
 		    G_trim_decimal(nbuf);



More information about the grass-commit mailing list