Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2084 closed defect (fixed)

ST_Within and ST_CoveredBy producing bad results after fix for #547

Reported by: darkpanda Owned by: pramsey
Priority: critical Milestone: PostGIS 1.5.8
Component: postgis Version: 1.5.X
Keywords: Cc:

Description

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.

Attachments (1)

0001-2084-ST_Within-and-ST_CoveredBy-producing-bad-result.patch (4.3 KB ) - added by darkpanda 11 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by pramsey, 11 years ago

Patch makes sense, the logic of the calls is reversed, but the cache uses the polygon-in-arg1 logic of other functions. Checking against my local regression now.

comment:2 by pramsey, 11 years ago

Resolution: fixed
Status: newclosed

Fixed at r10645.

comment:3 by robe, 11 years ago

Milestone: PostGIS 1.5.7PostGIS 1.5.8
Note: See TracTickets for help on using tickets.