[postgis-users] Differences between "&&" and Intersects

Graham Stewart graham at mobilefoundry.net
Tue Mar 21 09:50:51 PST 2006


Jeremy,

I'm pretty new to this too, however my understanding is that the &&
operator tests if the bounding boxes of the geometries intersect whereas
the Intersects function will test if the actual geometries intersect.

It's entirely possible for the bounding boxes of two polygons to
intersect when the polygons themselves do not. In your situation you'd
expect the && operator to return a superset containing the Intersects
results, but if you have a large dataset then it'll significantly speed
up your query as the && operator can take advantage of indices.

Graham


Jeremy Nix wrote:
> I'm new to PostGIS (and postgresql for that point), so I apologize if
> I'm missing something fundamental.  I've created a GIS table containing
> a geometry column.  I've also created a spatial index on this column.
> I'm now attempting to query the table based on a point.  I have 2
> different queries below.
>  
> Query 1) (longitude, latitude, and bufferInFeet are inputs)
>     geom geometry;
>     geom := Buffer(MakePoint(longitude, latitude),
> bufferInFeet/364560.0)
>     SELECT polyattributes, poly
>     FROM polygons
>     WHERE poly && geom
>  
> Query 2) (longitude, latitude, and bufferInFeet are inputs)
>     geom geometry;
>     geom := Buffer(MakePoint(longitude, latitude),
> bufferInFeet/364560.0)
>     SELECT polyattributes, poly
>     FROM polygons
>     WHERE poly && geom AND Intersects(poly, geom)
>  
> These queries return different results in particular cases that I was
> testing.  My question is why.  I assumed that the "&&" operator that is
> used with the spatial index performed some sort of intersects function
> with the bounding box (geom in this case).  If that is the case, then
> these queries would be functionally equivalent.  But, in my tests, I
> found that when I used Query 1, more results were returned than when I
> used Query 2.  Can somebody tell me why this is?
>  
> Thanks in advance for any help.
>  
> ________________________________
> Jeremy Nix
> Senior Application Developer
> Southwest Financial Services, Ltd.
> http://www.sfsltd.com <http://www.sfsltd.com/> 
>  
>  
>
>   
> ------------------------------------------------------------------------
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>   




More information about the postgis-users mailing list