ST_Within and ST_CoveredBy producing bad results after fix for #547
|Reported by:||darkpanda||Owned by:||pramsey|
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
, 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
. 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.