[postgis-tickets] r16668 - Ensure index filters on expanded boxes are large enough to encompass

Paul Ramsey pramsey at cleverelephant.ca
Tue Jul 24 01:50:08 PDT 2018


Author: pramsey
Date: 2018-07-24 13:50:08 -0700 (Tue, 24 Jul 2018)
New Revision: 16668

Modified:
   trunk/postgis/geography_measurement.c
   trunk/regress/tickets.sql
   trunk/regress/tickets_expected
Log:
Ensure index filters on expanded boxes are large enough to encompass
the radii they are searching, closes #4081


Modified: trunk/postgis/geography_measurement.c
===================================================================
--- trunk/postgis/geography_measurement.c	2018-07-24 13:46:23 UTC (rev 16667)
+++ trunk/postgis/geography_measurement.c	2018-07-24 20:50:08 UTC (rev 16668)
@@ -466,16 +466,20 @@
 {
 	GSERIALIZED *g = NULL;
 	GSERIALIZED *g_out = NULL;
-	double distance;
+	double unit_distance, distance;
 
 	/* Get a wholly-owned pointer to the geography */
 	g = PG_GETARG_GSERIALIZED_P_COPY(0);
 
 	/* Read our distance value and normalize to unit-sphere. */
-	distance = PG_GETARG_FLOAT8(1) / WGS84_RADIUS;
+	distance = PG_GETARG_FLOAT8(1);
+	/* Magic 1% expansion is to bridge difference between potential */
+	/* spheroidal input distance and fact that expanded box filter is */
+	/* calculated on sphere */
+	unit_distance = 1.01 * distance / WGS84_RADIUS;
 
 	/* Try the expansion */
-	g_out = gserialized_expand(g, distance);
+	g_out = gserialized_expand(g, unit_distance);
 
 	/* If the expansion fails, the return our input */
 	if ( g_out == NULL )

Modified: trunk/regress/tickets.sql
===================================================================
--- trunk/regress/tickets.sql	2018-07-24 13:46:23 UTC (rev 16667)
+++ trunk/regress/tickets.sql	2018-07-24 20:50:08 UTC (rev 16668)
@@ -1090,5 +1090,14 @@
 
 select '#4103', ST_Intersects(ST_PointOnSurface('0103000020110F0000010000000A000000000000C41E644741000000EEA2A75A41000000F420644741000000629EA75A410000007A2D644741000000E49FA75A41000000C02E644741000000409DA75A41000000286A64474100000064A4A75A410000007867644741000000FAA9A75A41000000E82B644741000000D2A2A75A41000000222D64474100000046A0A75A41000000242B6447410000006CA4A75A41000000C41E644741000000EEA2A75A41'::geometry), '0103000020110F0000010000000A000000000000C41E644741000000EEA2A75A41000000F420644741000000629EA75A410000007A2D644741000000E49FA75A41000000C02E644741000000409DA75A41000000286A64474100000064A4A75A410000007867644741000000FAA9A75A41000000E82B644741000000D2A2A75A41000000222D64474100000046A0A75A41000000242B6447410000006CA4A75A41000000C41E644741000000EEA2A75A41'::geometry);
 
+-- #4081
+select '#4081',
+ST_DWithin(a, b, 110575, true) as within_110575_true,
+ST_DWithin(a, b, 110576, true) as within_110576_true
+from (
+    select ST_GeogFromText('SRID=4326;POINT(1.0 2.0)') as a, ST_GeogFromText('SRID=4326;POINT(1.0 1.0)') as b
+) as points;
+
+
 -- Clean up
 DELETE FROM spatial_ref_sys;

Modified: trunk/regress/tickets_expected
===================================================================
--- trunk/regress/tickets_expected	2018-07-24 13:46:23 UTC (rev 16667)
+++ trunk/regress/tickets_expected	2018-07-24 20:50:08 UTC (rev 16668)
@@ -354,3 +354,4 @@
 NOTICE:  Your geometry dataset is not valid per OGC Specification. Please fix it with manual review of entries that are not ST_IsValid(geom). Retrying GEOS operation with ST_MakeValid of your input.
 NOTICE:  Self-intersection
 #4103|t
+#4081|f|t



More information about the postgis-tickets mailing list