[postgis-tickets] [SCM] PostGIS branch master updated. 3.1.0alpha2-10-g510b23d

git at osgeo.org git at osgeo.org
Wed Jul 29 03:22:54 PDT 2020


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".

The branch, master has been updated
       via  510b23dc037e1ea3d225e4632461f374b71e8849 (commit)
      from  672e6d06db6132bc7ad83685d4903b0b43eac8f9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 510b23dc037e1ea3d225e4632461f374b71e8849
Author: Raúl Marín <git at rmr.ninja>
Date:   Tue Jul 28 17:45:01 2020 +0200

    Use lwprint_double for printing box types
    
    Includes BOX2D, BOX3D, BOX2DF and GIDX
    
    Closes #4533 (Only for 3.1+)
    Closes https://github.com/postgis/postgis/pull/574

diff --git a/NEWS b/NEWS
index 5448752..357c5a5 100644
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@ Only tickets not included in 3.1.0alpha2
         - All output functions now respect the requested precision (without any limits).
         - The default precision is the same (9 for GeoJSON, 15 for everything else).
   - #4729, WKT/KML: Print doubles directly into stringbuffers (Raúl Marín)
+  - #4533, Use the standard coordinate printing system for box types (Raúl Marín)
 
 * Bug fixes *
   -
diff --git a/libpgcommon/gserialized_gist.c b/libpgcommon/gserialized_gist.c
index a1329ae..4aad26e 100644
--- a/libpgcommon/gserialized_gist.c
+++ b/libpgcommon/gserialized_gist.c
@@ -19,6 +19,7 @@
 /*#define POSTGIS_DEBUG_LEVEL 4*/
 
 #include "liblwgeom.h"         /* For standard geometry types. */
+#include "liblwgeom_internal.h"
 #include "lwgeom_pg.h"       /* For debugging macros. */
 #include "gserialized_gist.h"
 
@@ -30,30 +31,32 @@
 /* Generate human readable form for GIDX. */
 char* gidx_to_string(GIDX *a)
 {
-	char *str, *rv;
-	int i, ndims;
+	static const int precision = 12;
+	char tmp[8 + 8 * (OUT_MAX_BYTES_DOUBLE + 1)] = {'G', 'I', 'D', 'X', '(', 0};
+	int len = 5;
+	int ndims;
 
-	if ( a == NULL )
+	if (a == NULL)
 		return pstrdup("<NULLPTR>");
-	/* 4 (GIDX_MAX_DIM) *
-	 * 2 (MAX & MIN) *
-	 * 20 (Max representation (e.g. -3.40282346639e+38) [19] + space)
-	 * = 4*2*20 = 160
-	 * + 9 [ 'GIDX(' = 5, ','  = 1, ' )' = 2 + '\0' = 1]
-	 */
-	str = (char *)palloc(169);
-	rv = str;
+
 	ndims = GIDX_NDIMS(a);
 
-	str += sprintf(str, "GIDX(");
-	for ( i = 0; i < ndims; i++ )
-		str += sprintf(str, " %.12g", GIDX_GET_MIN(a,i));
-	str += sprintf(str, ",");
-	for ( i = 0; i < ndims; i++ )
-		str += sprintf(str, " %.12g", GIDX_GET_MAX(a,i));
-	str += sprintf(str, " )");
+	for (int i = 0; i < ndims; i++)
+	{
+		tmp[len++] = ' ';
+		len += lwprint_double(GIDX_GET_MIN(a, i), precision, &tmp[len]);
+	}
+	tmp[len++] = ',';
+
+	for (int i = 0; i < ndims; i++)
+	{
+		tmp[len++] = ' ';
+		len += lwprint_double(GIDX_GET_MAX(a, i), precision, &tmp[len]);
+	}
+
+	tmp[len++] = ')';
 
-	return rv;
+	return pstrdup(tmp);
 }
 
 /* Allocates a new GIDX on the heap of the requested dimensionality */
diff --git a/postgis/gserialized_gist_2d.c b/postgis/gserialized_gist_2d.c
index b6ce9a5..e5b2c27 100644
--- a/postgis/gserialized_gist_2d.c
+++ b/postgis/gserialized_gist_2d.c
@@ -46,6 +46,7 @@
 #include "../postgis_config.h"
 
 #include "liblwgeom.h"         /* For standard geometry types. */
+#include "liblwgeom_internal.h"
 #include "lwgeom_pg.h"       /* For debugging macros. */
 #include "gserialized_gist.h"	     /* For utility functions. */
 
@@ -116,14 +117,24 @@ typedef bool (*box2df_predicate)(const BOX2DF *a, const BOX2DF *b);
 
 static char* box2df_to_string(const BOX2DF *a)
 {
-	char *rv = NULL;
+	static const int precision = 12;
+	char tmp[13 + 4 * OUT_MAX_BYTES_DOUBLE] = {'B', 'O', 'X', '2', 'D', 'F', '(', 0};
+	int len = 7;
 
-	if ( a == NULL )
+	if (a == NULL)
 		return pstrdup("<NULLPTR>");
 
-	rv = palloc(128);
-	sprintf(rv, "BOX2DF(%.12g %.12g, %.12g %.12g)", a->xmin, a->ymin, a->xmax, a->ymax);
-	return rv;
+	len += lwprint_double(a->xmin, precision, &tmp[len]);
+	tmp[len++] = ' ';
+	len += lwprint_double(a->ymin, precision, &tmp[len]);
+	tmp[len++] = ',';
+	tmp[len++] = ' ';
+	len += lwprint_double(a->xmax, precision, &tmp[len]);
+	tmp[len++] = ' ';
+	len += lwprint_double(a->ymax, precision, &tmp[len]);
+	tmp[len++] = ')';
+
+	return pstrdup(tmp);
 }
 
 /* Allocate a new copy of BOX2DF */
diff --git a/postgis/lwgeom_box.c b/postgis/lwgeom_box.c
index 4368728..b9cab7d 100644
--- a/postgis/lwgeom_box.c
+++ b/postgis/lwgeom_box.c
@@ -34,6 +34,7 @@
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
 #include "liblwgeom.h"
+#include "liblwgeom_internal.h"
 
 #include <math.h>
 #include <float.h>
@@ -93,24 +94,30 @@ Datum BOX2D_in(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(BOX2D_out);
 Datum BOX2D_out(PG_FUNCTION_ARGS)
 {
-	char tmp[500]; /* big enough */
+	char tmp[500] = {'B', 'O', 'X', '(', 0}; /* big enough */
+	static const int precision = 15;
 	char *result;
-	int size;
+	int size = 0;
 
 	GBOX *box = (GBOX *)PG_GETARG_POINTER(0);
 	/* Avoid unaligned access to the gbox struct */
 	GBOX box_aligned;
 	memcpy(&box_aligned, box, sizeof(GBOX));
 
-	size = sprintf(tmp,
-		       "BOX(%.15g %.15g,%.15g %.15g)",
-		       box_aligned.xmin,
-		       box_aligned.ymin,
-		       box_aligned.xmax,
-		       box_aligned.ymax);
+	size = 4;
+	size += lwprint_double(box_aligned.xmin, precision, &tmp[size]);
+	tmp[size++] = ' ';
+	size += lwprint_double(box_aligned.ymin, precision, &tmp[size]);
+	tmp[size++] = ',';
+	size += lwprint_double(box_aligned.xmax, precision, &tmp[size]);
+	tmp[size++] = ' ';
+	size += lwprint_double(box_aligned.ymax, precision, &tmp[size]);
 
-	result= palloc(size+1); /* +1= null term */
-	memcpy(result,tmp,size+1);
+	tmp[size++] = ')';
+	size += 1;
+
+	result = palloc(size + 1); /* +1= null term */
+	memcpy(result, tmp, size + 1);
 	result[size] = '\0';
 
 	PG_RETURN_CSTRING(result);
diff --git a/postgis/lwgeom_box3d.c b/postgis/lwgeom_box3d.c
index 9a34500..28448f1 100644
--- a/postgis/lwgeom_box3d.c
+++ b/postgis/lwgeom_box3d.c
@@ -33,6 +33,7 @@
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
 #include "liblwgeom.h"
+#include "liblwgeom_internal.h"
 #include "lwgeom_box3d.h"
 
 #include <math.h>
@@ -40,8 +41,6 @@
 #include <string.h>
 #include <stdio.h>
 
-#define SHOW_DIGS_DOUBLE 15
-#define MAX_DIGS_DOUBLE (SHOW_DIGS_DOUBLE + 6 + 1 + 3 + 1)
 
 /**
  *  BOX3D_in - takes a string rep of BOX3D and returns internal rep
@@ -121,7 +120,9 @@ PG_FUNCTION_INFO_V1(BOX3D_out);
 Datum BOX3D_out(PG_FUNCTION_ARGS)
 {
 	BOX3D *bbox = (BOX3D *)PG_GETARG_POINTER(0);
-	int size;
+	static const int precision = 15;
+	static int size = OUT_MAX_BYTES_DOUBLE * 6 + 5 + 2 + 4 + 5 + 1; /* double * 6 + "BOX3D"+ "()" + commas + null */
+	int i = 0;
 	char *result;
 
 	if (bbox == NULL)
@@ -131,19 +132,26 @@ Datum BOX3D_out(PG_FUNCTION_ARGS)
 		PG_RETURN_CSTRING(result);
 	}
 
-	/* double digits + "BOX3D"+ "()" + commas + null */
-	size = MAX_DIGS_DOUBLE * 6 + 5 + 2 + 4 + 5 + 1;
-
 	result = (char *)palloc(size);
-
-	sprintf(result,
-		"BOX3D(%.15g %.15g %.15g,%.15g %.15g %.15g)",
-		bbox->xmin,
-		bbox->ymin,
-		bbox->zmin,
-		bbox->xmax,
-		bbox->ymax,
-		bbox->zmax);
+	result[i++] = 'B';
+	result[i++] = 'O';
+	result[i++] = 'X';
+	result[i++] = '3';
+	result[i++] = 'D';
+	result[i++] = '(';
+	i += lwprint_double(bbox->xmin, precision, &result[i]);
+	result[i++] = ' ';
+	i += lwprint_double(bbox->ymin, precision, &result[i]);
+	result[i++] = ' ';
+	i += lwprint_double(bbox->zmin, precision, &result[i]);
+	result[i++] = ',';
+	i += lwprint_double(bbox->xmax, precision, &result[i]);
+	result[i++] = ' ';
+	i += lwprint_double(bbox->ymax, precision, &result[i]);
+	result[i++] = ' ';
+	i += lwprint_double(bbox->zmax, precision, &result[i]);
+	result[i++] = ')';
+	result[i++] = '\0';
 
 	PG_RETURN_CSTRING(result);
 }
diff --git a/regress/core/in_geohash_expected b/regress/core/in_geohash_expected
index d10a378..35937cf 100644
--- a/regress/core/in_geohash_expected
+++ b/regress/core/in_geohash_expected
@@ -1,7 +1,7 @@
-box2dfromgeohash_01|BOX(-115.172816 36.114646,-115.172816 36.114646)
+box2dfromgeohash_01|BOX(-115.17281600000001 36.11464599999999,-115.172816 36.114646)
 box2dfromgeohash_02|BOX(-180 -90,180 90)
-box2dfromgeohash_03|BOX(-115.172816 36.114646,-115.172816 36.114646)
-box2dfromgeohash_04|BOX(-115.172816 36.114646,-115.172816 36.114646)
+box2dfromgeohash_03|BOX(-115.17281600000001 36.11464599999999,-115.172816 36.114646)
+box2dfromgeohash_04|BOX(-115.17281600000001 36.11464599999999,-115.172816 36.114646)
 geomfromgeohash_01|POLYGON((-115.17281600000001 36.11464599999999,-115.17281600000001 36.114646,-115.172816 36.114646,-115.172816 36.11464599999999,-115.17281600000001 36.11464599999999))
 geomfromgeohash_02|POLYGON((-180 -90,-180 90,180 90,180 -90,-180 -90))
 geomfromgeohash_03|POLYGON((-115.17281600000001 36.11464599999999,-115.17281600000001 36.114646,-115.172816 36.114646,-115.172816 36.11464599999999,-115.17281600000001 36.11464599999999))

-----------------------------------------------------------------------

Summary of changes:
 NEWS                             |  1 +
 libpgcommon/gserialized_gist.c   | 41 +++++++++++++++++++++-------------------
 postgis/gserialized_gist_2d.c    | 21 +++++++++++++++-----
 postgis/lwgeom_box.c             | 27 ++++++++++++++++----------
 postgis/lwgeom_box3d.c           | 38 ++++++++++++++++++++++---------------
 regress/core/in_geohash_expected |  6 +++---
 6 files changed, 82 insertions(+), 52 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list