[postgis-users] Point in Polygon query tolerance?

Michael Fuhr mike at fuhr.org
Sat Aug 4 03:59:00 PDT 2007


On Sat, Aug 04, 2007 at 12:20:32PM +0200, Frank Broniewski wrote:
> To my problem: I have a geology polygon table and a site point table. Now I 
> want to find out the site's geology. I do the following query
> 
> SELECT name FROM geo.geology AS c, arch.operation AS p WHERE c.the_geom && 
> p.op_centroid AND p.op_id = 20
> 
> for a single sample site. The query returns three rows, while it should be 
> just one. Another site returns even five rows as result.

The && operator is a fast check for bounding box overlaps that can
take advantage of indexes.  You'll need to restrict the result set
further by adding a more expensive test like one of the following:

contains(c.the_geom, p.op_centroid)
within(p.op_centroid, c.the_geom)
intersects(c.the_geom, p.op_centroid)
distance(c.the_geom, p.op_centroid) = 0

-- 
Michael Fuhr



More information about the postgis-users mailing list