[postgis-tickets] [SCM] PostGIS branch master updated. 939c30639e36c1d1c299bac589d38f369391b2ab

git at osgeo.org git at osgeo.org
Thu Dec 12 07:56:12 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, master has been updated
       via  939c30639e36c1d1c299bac589d38f369391b2ab (commit)
      from  bbbd77d0b9504281ad19731316ae7dd0ad7d9f6f (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 939c30639e36c1d1c299bac589d38f369391b2ab
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
    
    References #4600
    References #4602
    
    Closes https://github.com/postgis/postgis/pull/522

diff --git a/NEWS b/NEWS
index 10130b7..6139aa8 100644
--- a/NEWS
+++ b/NEWS
@@ -34,6 +34,7 @@ PostGIS 3.1.0
   - #4590, Fix pg_upgrade issue with st_linecrossingdirection (Raúl Marín)
   - #4592, Add missing CPPFLAGS in multiple Makefiles (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
 2019/10/xx
diff --git a/postgis/lwgeom_functions_basic.c b/postgis/lwgeom_functions_basic.c
index 1a02b0a..f866e49 100644
--- a/postgis/lwgeom_functions_basic.c
+++ b/postgis/lwgeom_functions_basic.c
@@ -2059,6 +2059,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");
 
@@ -2067,9 +2068,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);
 
 	margin = PG_GETARG_FLOAT8(4);
 	/* shrinking by more than 50% would eliminate the tile outright */
@@ -2099,7 +2108,7 @@ Datum ST_TileEnvelope(PG_FUNCTION_ARGS)
 	 * 1 margin (100%) is the same as a single tile width
 	 * if the size of the tile with margins span more than the total number of tiles,
 	 * reset x1/x2 to the bounds
-	*/
+	 */
 	if ((1 + margin * 2) > worldTileSize)
 	{
 		x1 = bbox.xmin;
diff --git a/regress/core/regress_expected b/regress/core/regress_expected
index 4b3d7bc..f07b639 100644
--- a/regress/core/regress_expected
+++ b/regress/core/regress_expected
@@ -196,21 +196,21 @@ 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))
 235|POLYGON((0 -12.5,0 0,25 0,25 -12.5,0 -12.5))
-236|SRID=3857;POLYGON((-20037510 -20037510,-20037510 20037510,20037510 20037510,20037510 -20037510,-20037510 -20037510))
-237|SRID=3857;POLYGON((-22041261 -2003751,-22041261 20037510,2003751 20037510,2003751 -2003751,-22041261 -2003751))
-238|SRID=3857;POLYGON((-15028132.5 -20037510,-15028132.5 -5009377.5,5009377.5 -5009377.5,5009377.5 -20037510,-15028132.5 -20037510))
+236|SRID=3857;POLYGON((-20037508.342789 -20037508.342789,-20037508.342789 20037508.342789,20037508.342789 20037508.342789,20037508.342789 -20037508.342789,-20037508.342789 -20037508.342789))
+237|SRID=3857;POLYGON((-22041259.1770679 -2003750.8342789,-22041259.1770679 20037508.342789,2003750.8342789 20037508.342789,2003750.8342789 -2003750.8342789,-22041259.1770679 -2003750.8342789))
+238|SRID=3857;POLYGON((-15028131.2570918 -20037508.342789,-15028131.2570918 -5009377.08569725,5009377.08569725 -5009377.08569725,5009377.08569725 -20037508.342789,-15028131.2570918 -20037508.342789))
 239|SRID=3857;POLYGON((0 0,0 0,0 0,0 0,0 0))
 ERROR:  ST_TileEnvelope: Margin must not be less than -50%, margin=-0.510000
-241|SRID=3857;POLYGON((-4007502 -4007502,-4007502 4007502,4007502 4007502,4007502 -4007502,-4007502 -4007502))
-250|SRID=3857;POLYGON((-8296781.484375 4852834.453125,-8296781.484375 4891970.21484375,-8257645.72265625 4891970.21484375,-8257645.72265625 4852834.453125,-8296781.484375 4852834.453125))
-251|SRID=3857;POLYGON((-8300695.06054688 4848920.87695312,-8300695.06054688 4895883.79101562,-8253732.14648438 4895883.79101562,-8253732.14648438 4848920.87695312,-8300695.06054688 4848920.87695312))
-252|SRID=3857;POLYGON((-8316349.36523438 4833266.57226562,-8316349.36523438 4911538.09570312,-8238077.84179688 4911538.09570312,-8238077.84179688 4833266.57226562,-8316349.36523438 4833266.57226562))
-253|SRID=3857;POLYGON((-8375053.0078125 4774562.9296875,-8375053.0078125 4970241.73828125,-8179374.19921875 4970241.73828125,-8179374.19921875 4774562.9296875,-8375053.0078125 4774562.9296875))
-254|SRID=3857;POLYGON((-8285040.75585938 4864575.18164062,-8285040.75585938 4880229.48632812,-8269386.45117188 4880229.48632812,-8269386.45117188 4864575.18164062,-8285040.75585938 4864575.18164062))
+241|SRID=3857;POLYGON((-4007501.6685578 -4007501.6685578,-4007501.6685578 4007501.6685578,4007501.6685578 4007501.6685578,4007501.6685578 -4007501.6685578,-4007501.6685578 -4007501.6685578))
+250|SRID=3857;POLYGON((-8296780.79818607 4852834.05176921,-8296780.79818607 4891969.81025122,-8257645.03970406 4891969.81025122,-8257645.03970406 4852834.05176921,-8296780.79818607 4852834.05176921))
+251|SRID=3857;POLYGON((-8300694.37403427 4848920.47592101,-8300694.37403427 4895883.38609942,-8253731.46385586 4895883.38609942,-8253731.46385586 4848920.47592101,-8300694.37403427 4848920.47592101))
+252|SRID=3857;POLYGON((-8316348.67742708 4833266.17252821,-8316348.67742708 4911537.68949223,-8238077.16046306 4911537.68949223,-8238077.16046306 4833266.17252821,-8316348.67742708 4833266.17252821))
+253|SRID=3857;POLYGON((-8375052.31515009 4774562.53480519,-8375052.31515009 4970241.32721524,-8179373.52274004 4970241.32721524,-8179373.52274004 4774562.53480519,-8375052.31515009 4774562.53480519))
+254|SRID=3857;POLYGON((-8285040.07064147 4864574.77931381,-8285040.07064147 4880229.08270662,-8269385.76724866 4880229.08270662,-8269385.76724866 4864574.77931381,-8285040.07064147 4864574.77931381))

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

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


hooks/post-receive
-- 
PostGIS


More information about the postgis-tickets mailing list