[postgis-tickets] [SCM] PostGIS branch master updated. 3.1.0alpha2-9-g672e6d0

git at osgeo.org git at osgeo.org
Wed Jul 29 01:53:57 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  672e6d06db6132bc7ad83685d4903b0b43eac8f9 (commit)
      from  13437122770db9f07be062feddba80210bee0a0d (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 672e6d06db6132bc7ad83685d4903b0b43eac8f9
Author: Raúl Marín <git at rmr.ninja>
Date:   Tue Jul 28 16:17:07 2020 +0200

    WKT/KML: Print doubles directly into stringbuffers
    
    Closes https://github.com/postgis/postgis/pull/573
    Closes #4729

diff --git a/NEWS b/NEWS
index 692b678..5448752 100644
--- a/NEWS
+++ b/NEWS
@@ -15,6 +15,7 @@ Only tickets not included in 3.1.0alpha2
         - The precision parameter now also affects the scientific notation (before it was fixed [5-8]).
         - 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)
 
 * Bug fixes *
   -
diff --git a/liblwgeom/lwout_kml.c b/liblwgeom/lwout_kml.c
index 1e95487..45ff523 100644
--- a/liblwgeom/lwout_kml.c
+++ b/liblwgeom/lwout_kml.c
@@ -110,9 +110,7 @@ ptarray_to_kml2_sb(const POINTARRAY *pa, int precision, stringbuffer_t *sb)
 		for (j = 0; j < dims; j++)
 		{
 			if ( j ) stringbuffer_append_len(sb,",",1);
-			char coord[OUT_DOUBLE_BUFFER_SIZE];
-			int len = lwprint_double(d[j], precision, coord);
-			stringbuffer_append_len(sb, coord, len);
+			stringbuffer_append_double(sb, d[j], precision);
 		}
 	}
 	return LW_SUCCESS;
diff --git a/liblwgeom/lwout_wkt.c b/liblwgeom/lwout_wkt.c
index ac3430f..d8f9743 100644
--- a/liblwgeom/lwout_wkt.c
+++ b/liblwgeom/lwout_wkt.c
@@ -76,6 +76,19 @@ static void empty_to_wkt_sb(stringbuffer_t *sb)
 	stringbuffer_append_len(sb, "EMPTY", 5);
 }
 
+inline static void
+coordinate_to_wkt_sb(double *coords, stringbuffer_t *sb, uint32_t dimensions, int precision)
+{
+	uint32_t d = 0;
+	stringbuffer_append_double(sb, coords[d], precision);
+
+	for (d = 1; d < dimensions; d++)
+	{
+		stringbuffer_append_len(sb, " ", 1);
+		stringbuffer_append_double(sb, coords[d], precision);
+	}
+}
+
 /*
 * Point array is a list of coordinates. Depending on output mode,
 * we may suppress some dimensions. ISO and Extended formats include
@@ -85,33 +98,29 @@ static void ptarray_to_wkt_sb(const POINTARRAY *ptarray, stringbuffer_t *sb, int
 {
 	/* OGC only includes X/Y */
 	uint32_t dimensions = 2;
-	uint32_t i, j;
-	char coord[OUT_DOUBLE_BUFFER_SIZE];
 
 	/* ISO and extended formats include all dimensions */
 	if ( variant & ( WKT_ISO | WKT_EXTENDED ) )
 		dimensions = FLAGS_NDIMS(ptarray->flags);
 
+	stringbuffer_makeroom(sb, 2 + ((OUT_MAX_BYTES_DOUBLE + 1) * dimensions * ptarray->npoints));
 	/* Opening paren? */
 	if ( ! (variant & WKT_NO_PARENS) )
 		stringbuffer_append_len(sb, "(", 1);
 
 	/* Digits and commas */
-	for (i = 0; i < ptarray->npoints; i++)
+	if (ptarray->npoints)
 	{
-		double *dbl_ptr = (double*)getPoint_internal(ptarray, i);
+		uint32_t i = 0;
 
-		/* Commas before ever coord but the first */
-		if ( i > 0 )
-			stringbuffer_append_len(sb, ",", 1);
+		double *dbl_ptr = (double *)getPoint_internal(ptarray, i);
+		coordinate_to_wkt_sb(dbl_ptr, sb, dimensions, precision);
 
-		for (j = 0; j < dimensions; j++)
+		for (i = 1; i < ptarray->npoints; i++)
 		{
-			/* Spaces before every ordinate but the first */
-			if ( j > 0 )
-				stringbuffer_append_len(sb, " ", 1);
-			int len = lwprint_double(dbl_ptr[j], precision, coord);
-			stringbuffer_append_len(sb, coord, len);
+			stringbuffer_append_len(sb, ",", 1);
+			dbl_ptr = (double *)getPoint_internal(ptarray, i);
+			coordinate_to_wkt_sb(dbl_ptr, sb, dimensions, precision);
 		}
 	}
 
diff --git a/liblwgeom/stringbuffer.h b/liblwgeom/stringbuffer.h
index eac9ceb..a0324f6 100644
--- a/liblwgeom/stringbuffer.h
+++ b/liblwgeom/stringbuffer.h
@@ -105,4 +105,11 @@ stringbuffer_append(stringbuffer_t *s, const char *a)
 	int alen = strlen(a); /* Length of string to append */
 	stringbuffer_append_len(s, a, alen);
 }
+
+inline static void
+stringbuffer_append_double(stringbuffer_t *s, double d, int precision)
+{
+	stringbuffer_makeroom(s, OUT_MAX_BYTES_DOUBLE);
+	s->str_end += lwprint_double(d, precision, s->str_end);
+}
 #endif /* _STRINGBUFFER_H */

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

Summary of changes:
 NEWS                     |  1 +
 liblwgeom/lwout_kml.c    |  4 +---
 liblwgeom/lwout_wkt.c    | 35 ++++++++++++++++++++++-------------
 liblwgeom/stringbuffer.h |  7 +++++++
 4 files changed, 31 insertions(+), 16 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list