Home | Previous Page | Next Page   Using the R-Tree Secondary Access Method > Performing Nearest-Neighbor Searches >

Example

The following example shows how to perform a nearest-neighbor search using the IBM Informix Spatial DataBlade module. The SE_Nearest function allows you to perform the search.

The cities table was created with the following statement. It contains the names and locations of approximately 300 world cities.

CREATE TABLE cities (name varchar(255),
                     locn ST_Point);

An R-tree index is created on the locn column:

CREATE INDEX cities_idx ON cities (locn ST_Geometry_ops) 
   USING RTREE;

UPDATE STATISTICS FOR TABLE cities (locn);

Now search for the five cities nearest London:

SELECT FIRST 5 name FROM cities
   WHERE SE_Nearest(locn, '0 point(0 51)');

The query returns the following results:

name  London

name  Birmingham

name  Paris

name  Nantes

name  Amsterdam
Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]