[postgis-users] use of spatial index in nearest neighbour query ?

Smith Roman autisi at yahoo.com
Fri Sep 4 03:20:05 PDT 2009


Hi,I will like to find out if this nearest neighbour query uses a postgis spatial index. The query is supposed to get the nearest atm's (POI) around a given location.SELECT gid, descriptio, name, address, suburb, AsText(the_geom), 
           ST_Distance(ST_Transform(the_geom, 26331), ST_Transform(setsrid(makepoint(3.3315343, 6.5593127), 4326), 26331)) as dist FROM lagos_poi84
             WHERE st_dwithin(ST_Transform(the_geom, 26331), ST_Transform(setsrid(makepoint(3.3315343, 6.5593127), 4326), 26331), 50000) 
            and suburb ~* '' and descriptio ~* 'atm' AND name ~* '' ORDER BY dist limit 50

I created an index on the transformed geometry as follows
CREATE INDEX "lagos_poi84UTM26331_idx" ON "public"."lagos_poi84" USING GIST ( ST_Transform("the_geom",
 26331) ); 		 


In the postgis manual, it was said that the st_dwithin() function uses a spatial index if available. Also, how can tell when a spatial query in postgis is using a spatial index ?Cheers,Roman.


      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20090904/37fece95/attachment.html>


More information about the postgis-users mailing list