From 0a08c16dc25a3549cc2b9ec6d59121ab34c4494a Mon Sep 17 00:00:00 2001 From: Paul Ramsey Date: Tue, 24 Jul 2018 20:50:08 +0000 Subject: [PATCH] Ensure index filters on expanded boxes are large enough to encompass the radii they are searching, closes #4081 git-svn-id: http://svn.osgeo.org/postgis/trunk@16668 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/geography_measurement.c | 10 +++++++--- regress/tickets.sql | 9 +++++++++ regress/tickets_expected | 1 + 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/postgis/geography_measurement.c b/postgis/geography_measurement.c index 9deba4fce..5d3781421 100644 --- a/postgis/geography_measurement.c +++ b/postgis/geography_measurement.c @@ -466,16 +466,20 @@ Datum geography_expand(PG_FUNCTION_ARGS) { 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 ) diff --git a/regress/tickets.sql b/regress/tickets.sql index eedeafbc4..e4d8bbd3a 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -1090,5 +1090,14 @@ select '#4089', st_astext(st_geomfromtwkb(st_AsTWKB(st_GeometryFromText('LINESTR 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; diff --git a/regress/tickets_expected b/regress/tickets_expected index e727304ea..1a874187a 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -354,3 +354,4 @@ NOTICE: Self-intersection 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 -- 2.40.0