[postgis-tickets] [SCM] PostGIS branch stable-3.0 updated. 531bc44162c2b3636887eee514aa6c5617589415

git at osgeo.org git at osgeo.org
Thu Dec 12 09:57:58 PST 2019


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, stable-3.0 has been updated
       via  531bc44162c2b3636887eee514aa6c5617589415 (commit)
      from  6a44fcb9885463754e60a05483099ab18d8bccfd (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 531bc44162c2b3636887eee514aa6c5617589415
Author: Raúl Marín <git at rmr.ninja>
Date:   Thu Dec 12 16:11:34 2019 +0100

    ST_TileEnvelope: Improve precision by calculating the input bbox
    
    Closes #4600

diff --git a/NEWS b/NEWS
index f549ada..d4d946b 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,7 @@ XXXX/XX/XX
   - #4588, Fix update when st_union(geometry) doesn't exist (Raúl Marín)
   - #4590, Fix pg_upgrade issue with st_linecrossingdirection (Raúl Marín)
   - #4599, ST_AddPoint: Accept -1 as a valid position (Raúl Marín)
+  - #4600, Improve precision of ST_TileEnvelope (Raúl Marín)
 
 
 PostGIS 3.0.0
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 60363fb..b48dc8f 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2042,6 +2042,7 @@ Datum ST_TileEnvelope(PG_FUNCTION_ARGS)
 	   srid of the object is EPSG:3857. */
 	int32_t srid;
 	GBOX bbox;
+	LWGEOM *g = NULL;
 
 	POSTGIS_DEBUG(2, "ST_TileEnvelope called");
 
@@ -2050,9 +2051,17 @@ Datum ST_TileEnvelope(PG_FUNCTION_ARGS)
 	y = PG_GETARG_INT32(2);
 
 	bounds = PG_GETARG_GSERIALIZED_P(3);
-	if(gserialized_get_gbox_p(bounds, &bbox) != LW_SUCCESS)
-		elog(ERROR, "%s: Empty bounds", __func__);
-	srid = gserialized_get_srid(bounds);
+	/*
+	 * We deserialize the geometry and recalculate the bounding box here to get
+	 * 64b floating point precision. The serialized bbox has 32b float is not
+	 * precise enough with big numbers such as the ones used in the default
+	 * parameters, e.g: -20037508.3427892 is transformed into -20037510
+	 */
+	g = lwgeom_from_gserialized(bounds);
+	if (lwgeom_calculate_gbox(g, &bbox) != LW_SUCCESS)
+		elog(ERROR, "%s: Unable to compute bbox", __func__);
+	srid = g->srid;
+	lwgeom_free(g);
 
 	boundsWidth  = bbox.xmax - bbox.xmin;
 	boundsHeight = bbox.ymax - bbox.ymin;
diff --git a/regress/core/regress_expected b/regress/core/regress_expected
index d82fe5c..cde8673 100644
--- a/regress/core/regress_expected
+++ b/regress/core/regress_expected
@@ -196,9 +196,9 @@ ERROR:  geometry contains non-closed rings
 226|t
 ERROR:  ST_TileEnvelope: Invalid tile zoom value, -1
 ERROR:  ST_TileEnvelope: Invalid tile y value, 1
-229|SRID=3857;POLYGON((-20037510 -20037510,-20037510 20037510,20037510 20037510,20037510 -20037510,-20037510 -20037510))
-230|SRID=3857;POLYGON((0 -2504688.75,0 0,2504688.75 0,2504688.75 -2504688.75,0 -2504688.75))
-231|SRID=3857;POLYGON((17532821.25 -20037510,17532821.25 -17532821.25,20037510 -17532821.25,20037510 -20037510,17532821.25 -20037510))
+229|SRID=3857;POLYGON((-20037508.342789 -20037508.342789,-20037508.342789 20037508.342789,20037508.342789 20037508.342789,20037508.342789 -20037508.342789,-20037508.342789 -20037508.342789))
+230|SRID=3857;POLYGON((0 -2504688.54284862,0 0,2504688.54284862 0,2504688.54284862 -2504688.54284862,0 -2504688.54284862))
+231|SRID=3857;POLYGON((17532819.7999404 -20037508.342789,17532819.7999404 -17532819.7999404,20037508.342789 -17532819.7999404,20037508.342789 -20037508.342789,17532819.7999404 -20037508.342789))
 232|POLYGON((0 -12.5,0 0,12.5 0,12.5 -12.5,0 -12.5))
 233|POLYGON((87.5 -100,87.5 -87.5,100 -87.5,100 -100,87.5 -100))
 234|POLYGON((-100 87.5,-100 100,-87.5 100,-87.5 87.5,-100 87.5))

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

Summary of changes:
 NEWS                             |  1 +
 postgis/lwgeom_functions_basic.c | 15 ++++++++++++---
 regress/core/regress_expected    |  6 +++---
 3 files changed, 16 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list