[GRASS-SVN] r37983 - in grass/branches/releasebranch_6_4: general/g.region lib/gis

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


Author: hamish
Date: 2009-06-19 21:39:17 -0400 (Fri, 19 Jun 2009)
New Revision: 37983

Modified:
   grass/branches/releasebranch_6_4/general/g.region/printwindow.c
   grass/branches/releasebranch_6_4/lib/gis/wind_format.c
Log:
output correct precision for different projection types (bugs #654 and #335; merge from devbr6)

Modified: grass/branches/releasebranch_6_4/general/g.region/printwindow.c
===================================================================
--- grass/branches/releasebranch_6_4/general/g.region/printwindow.c	2009-06-20 01:31:27 UTC (rev 37982)
+++ grass/branches/releasebranch_6_4/general/g.region/printwindow.c	2009-06-20 01:39:17 UTC (rev 37983)
@@ -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/releasebranch_6_4/lib/gis/wind_format.c
===================================================================
--- grass/branches/releasebranch_6_4/lib/gis/wind_format.c	2009-06-20 01:31:27 UTC (rev 37982)
+++ grass/branches/releasebranch_6_4/lib/gis/wind_format.c	2009-06-20 01:39:17 UTC (rev 37983)
@@ -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,20 +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. */
-    sprintf(buf, "%.8f", value);
+    if (full_prec)
+	sprintf(buf, "%.15g", value);
+    else
+	sprintf(buf, "%.8f", value);
+
     G_trim_decimal(buf);
 
-    return 0;
+    return;
 }



More information about the grass-commit mailing list