se_nearest.sql 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. -- This example demonstrates how to use SE_Nearest to perform
  2. -- a nearest-neighbor query.
  3. -- IMPORTANT:
  4. -- 1. This function is only available with the 9.3 version of
  5. -- Informix Dynamic Server.
  6. -- 2. You must create an R-Tree index to do nearest-neighbor
  7. -- queries.
  8. -- Step 1. Create the cities table which will contains the names
  9. -- and locations of world cities
  10. CREATE TABLE cities (name varchar(255),
  11. locn ST_Point);
  12. -- Step 2. Populate this table with data from a DB-Access load file.
  13. -- This data file is included with the Spatial DataBlade Module as
  14. -- part of this example. It contains the names and locations of
  15. -- approximately 300 world cities.
  16. LOAD FROM cities.load INSERT INTO cities;
  17. -- Step 3. Create an R-tree index on the locn column.
  18. CREATE INDEX cities_idx ON cities (locn ST_Geometry_ops) USING RTREE;
  19. UPDATE STATISTICS FOR TABLE cities (locn);
  20. -- Step 4. Try it! Find the 5 cities nearest London:
  21. SELECT FIRST 5 name FROM cities
  22. WHERE SE_Nearest(locn, '0 point(0 51)');