[postgis-tickets] r15295 - Fix for 32-bit lwprint to support ST_AsLatLonText
Regina Obe
lr at pcorp.us
Fri Jan 27 20:10:49 PST 2017
Author: robe
Date: 2017-01-27 20:10:49 -0800 (Fri, 27 Jan 2017)
New Revision: 15295
Modified:
branches/2.3/liblwgeom/lwprint.c
Log:
Fix for 32-bit lwprint to support ST_AsLatLonText
References #3688 for PostGIS 2.3.2
Modified: branches/2.3/liblwgeom/lwprint.c
===================================================================
--- branches/2.3/liblwgeom/lwprint.c 2017-01-25 23:46:00 UTC (rev 15294)
+++ branches/2.3/liblwgeom/lwprint.c 2017-01-28 04:10:49 UTC (rev 15295)
@@ -106,6 +106,8 @@
int sec_dec_digits = 0;
int sec_piece = -1;
+ int round_pow = 0;
+
int format_length = ((NULL == format) ? 0 : strlen(format));
char * result;
@@ -313,8 +315,8 @@
degrees = val;
if (min_digits > 0)
{
- degrees = (long)degrees;
- minutes = fmod(val * 10, 10) * 6;
+ /* Break degrees to integer and use fraction for minutes */
+ minutes = modf(val, °rees) * 60;
}
if (sec_digits > 0)
{
@@ -322,8 +324,17 @@
{
lwerror("Bad format, cannot include seconds (SS.SSS) without including minutes (MM.MMM).");
}
- minutes = (long)minutes;
- seconds = (val - (degrees + (minutes / 60))) * 3600;
+ seconds = modf(minutes, &minutes) * 60;
+ if (sec_piece >= 0)
+ {
+ /* See if the formatted seconds round up to 60. If so, increment minutes and reset seconds. */
+ round_pow = pow(10, sec_dec_digits);
+ if (floorf(seconds * round_pow) / round_pow >= 60)
+ {
+ minutes += 1;
+ seconds = 0;
+ }
+ }
}
/* Handle the compass direction. If not using compass dir, display degrees as a positive/negative number. */
More information about the postgis-tickets
mailing list