[postgis-users] Overlaps query

Nicolas Ribot nicky666 at gmail.com
Fri May 25 01:11:34 PDT 2007


> Thanks for your answer. I have tried this before.
>
> SELECT COUNT(a.id) FROM tbl1 a, tbl1 b WHERE a.geom && b.geom and a.id <>
> b.id
>
> But the result differs from my other query. Regarding to the PostGIS doc at
> http://postgis.refractions.net/docs/ch06.html the &&
> operator does not check the spatial overlap of two geometries, it checks if
> the bounding boxes of thw geometries overlap. But in my case I need to check
> if two geometries spatially overlap. Perhaps there is a possibility to make
> this faster in some way.
>

Hi,

you have to use both operators !
&& forces the use of GiST index and performs a primary search,
filtering out candidates whose bbox do not overlap.
Then, overlaps() performs a test on actual geometries.

As a general practice, always use the && operator with geographic
operators/predicates.
You can also explain analyse your query to see if index will be used.

Nicolas



More information about the postgis-users mailing list