[postgis] Efficiency of a bounding box query vs distance()

Dave Blasby dblasby at refractions.net
Tue Feb 26 08:52:56 PST 2002


thebanker95065 wrote:
> I am relatively new to PostGIS, and I haven't found much on this, so
> here goes--
> 
> Say I have built the GiST indexes on my table.  I am curious about
> the efficiency of doing a query that checks to see everything inside
> of a predetermined bounding box vs a query that does something
> like 'where distance(the_geom,'POINT(x y)') <25'.  So basically a
> circle radius vs a square box. 

Its much more efficient to do a bounding box search because:
1. its really easy (just a few calculations)
2. the GiST index can be used.

If you really do want to do circle-distances for your application then
you should do a:

select * from <table> where distance(the_geom,'POINT(x y)') <25 and
the_geom && expand_bbox('POINT(x y)'::geometry,25)

This will do an index search to find everything thats within a box,
centred at (x y), and has sides of length 2*25=50.
This is done using the GiST index, so it will VERY quickly get a bunch
of geometries that approximate your 
circle-distance function.  The approximate results will then be checked
by the expensive distance(...) function.

dave

------------------------ Yahoo! Groups Sponsor ---------------------~-->
Tiny Wireless Camera under $80!
Order Now! FREE VCR Commander!
Click Here - Only 1 Day Left!
http://us.click.yahoo.com/nuyOHD/7.PDAA/yigFAA/PhFolB/TM
---------------------------------------------------------------------~->

To unsubscribe from this group, send an email to:
postgis-unsubscribe at yahoogroups.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 





More information about the postgis-users mailing list