[postgis-tickets] [SCM] PostGIS branch master updated. 892fcde0d9cef66b215a149a290c2bcf0a7879c8
git at osgeo.org
git at osgeo.org
Mon Jan 27 02:14:55 PST 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 892fcde0d9cef66b215a149a290c2bcf0a7879c8 (commit)
from 0752db58ac990161981de417248edb918318f17f (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 892fcde0d9cef66b215a149a290c2bcf0a7879c8
Author: Raúl Marín <git at rmr.ninja>
Date: Fri Jan 17 18:17:54 2020 +0100
Geojson: Print doubles directly on the output buffer
Closes #4615
Closes https://github.com/postgis/postgis/pull/537
diff --git a/NEWS b/NEWS
index b4539b9..8d1a472 100644
--- a/NEWS
+++ b/NEWS
@@ -31,6 +31,7 @@ PostGIS 3.1.0
- #4589, Disable C asserts when building without "--enable-debug" (Raúl Marín)
- #4543, Introduce ryu to print doubles (Raúl Marín)
- #4626, Support pkg-config for libxml2 (Bas Couwenberg)
+ - #4615, Speed up geojson output (Raúl Marín)
* Bug fixes *
- #4544, Fix leak when parsing a WKT geometry_list (Raúl Marín)
diff --git a/liblwgeom/lwout_geojson.c b/liblwgeom/lwout_geojson.c
index f571279..c9c7888 100644
--- a/liblwgeom/lwout_geojson.c
+++ b/liblwgeom/lwout_geojson.c
@@ -722,49 +722,56 @@ asgeojson_geom_buf(const LWGEOM *geom, char *output, GBOX *bbox, int precision)
static size_t
pointArray_to_geojson(POINTARRAY *pa, char *output, int precision)
{
- uint32_t i;
- char *ptr;
- char x[OUT_DOUBLE_BUFFER_SIZE];
- char y[OUT_DOUBLE_BUFFER_SIZE];
- char z[OUT_DOUBLE_BUFFER_SIZE];
+ char *ptr = output;
assert ( precision <= OUT_MAX_DOUBLE_PRECISION );
- ptr = output;
- /* TODO: rewrite this loop to be simpler and possibly quicker */
if (!FLAGS_GET_Z(pa->flags))
{
- for (i=0; i<pa->npoints; i++)
+ for (uint32_t i = 0; i < pa->npoints; i++)
{
- const POINT2D *pt;
- pt = getPoint2d_cp(pa, i);
-
- lwprint_double(
- pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
- lwprint_double(
- pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
-
- if ( i ) ptr += sprintf(ptr, ",");
- ptr += sprintf(ptr, "[%s,%s]", x, y);
+ if (i)
+ {
+ *ptr = ',';
+ ptr++;
+ }
+ const POINT2D *pt = getPoint2d_cp(pa, i);
+
+ *ptr = '[';
+ ptr++;
+ ptr += lwprint_double(pt->x, precision, ptr, OUT_DOUBLE_BUFFER_SIZE);
+ *ptr = ',';
+ ptr++;
+ ptr += lwprint_double(pt->y, precision, ptr, OUT_DOUBLE_BUFFER_SIZE);
+ *ptr = ']';
+ ptr++;
}
}
else
{
- for (i=0; i<pa->npoints; i++)
+ for (uint32_t i = 0; i < pa->npoints; i++)
{
- const POINT3D *pt = getPoint3d_cp(pa, i);
-
- lwprint_double(
- pt->x, precision, x, OUT_DOUBLE_BUFFER_SIZE);
- lwprint_double(
- pt->y, precision, y, OUT_DOUBLE_BUFFER_SIZE);
- lwprint_double(
- pt->z, precision, z, OUT_DOUBLE_BUFFER_SIZE);
+ if (i)
+ {
+ *ptr = ',';
+ ptr++;
+ }
- if ( i ) ptr += sprintf(ptr, ",");
- ptr += sprintf(ptr, "[%s,%s,%s]", x, y, z);
+ const POINT3D *pt = getPoint3d_cp(pa, i);
+ *ptr = '[';
+ ptr++;
+ ptr += lwprint_double(pt->x, precision, ptr, OUT_DOUBLE_BUFFER_SIZE);
+ *ptr = ',';
+ ptr++;
+ ptr += lwprint_double(pt->y, precision, ptr, OUT_DOUBLE_BUFFER_SIZE);
+ *ptr = ',';
+ ptr++;
+ ptr += lwprint_double(pt->z, precision, ptr, OUT_DOUBLE_BUFFER_SIZE);
+ *ptr = ']';
+ ptr++;
}
}
+ *ptr = '\0';
return (ptr-output);
}
-----------------------------------------------------------------------
Summary of changes:
NEWS | 1 +
liblwgeom/lwout_geojson.c | 65 ++++++++++++++++++++++++++---------------------
2 files changed, 37 insertions(+), 29 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list