[postgis-devel] [PostGIS] #2084: ST_Within and ST_CoveredBy producing bad results after fix for #547

PostGIS trac at osgeo.org
Mon Nov 5 15:41:48 PST 2012

#2084: ST_Within and ST_CoveredBy producing bad results after fix for #547
 Reporter:  darkpanda  |       Owner:  pramsey      
     Type:  defect     |      Status:  new          
 Priority:  critical   |   Milestone:  PostGIS 1.5.7
Component:  postgis    |     Version:  1.5.X        
 Keywords:             |  
 It appears that the patch that closed off #547 (ST_contains memory problem
 when used between polygon and mixed geometry) in r10186 causes ST_Within
 and ST_CoveredBy to produce incorrect results. This can sometimes lead to
 true values being returned when false values are the correct results.

 The lines in postgis/lwgeom_geos.c that populate the cache with polygons
 seem to be inserting the wrong geometries into the cache. In both of the
 function definitions for ```within``` and ```coveredby```, the lines read

 poly_cache = GetRtreeCache(fcinfo, lwgeom, SERIALIZED_FORM(geom1));

 but geom1 refers to the point, not the polygon. The lines should read

 poly_cache = GetRtreeCache(fcinfo, lwgeom, SERIALIZED_FORM(geom2));

 The problem was never noticed before because the cache wasn't being used
 effectively, but the patch to #547 enabled the cache and thus the
 unexpected results.

 Attached is a patch for the 1.5 branch that should fix these lines and
 includes some regression tests for ```regress/tickets.sql```. The
 geometries used for the tests are variations on the ones we happened to be
 using when we noticed this behaviour on one of our servers but could be
 replaced with simpler tests if desired.

Ticket URL: <http://trac.osgeo.org/postgis/ticket/2084>
PostGIS <http://trac.osgeo.org/postgis/>
The PostGIS Trac is used for bug, enhancement & task tracking, a user and developer wiki, and a view into the subversion code repository of PostGIS project.

More information about the postgis-devel mailing list