使用者の手引きおよび解説書

サンプル・プログラムの断片

索引が作成されて SQL で使用される仕組みを示した次の例を考慮してください。 CREATE INDEX および CREATE INDEX EXTENSION コマンドの詳細については、 SQL 解説書 を参照することができます。 索引を作成した後は、 地理情報の関数と述部を使用する標準的な DDL および DML ステートメントを発行できます。

create table customers (cid int, addr varchar(40), ..., loc db2gse.ST_Point)
create table stores (sid int, addr varchar(40), ..., loc db2gse.ST_Point,
 zone db2gse.ST_Polygon)
create index customersx1 on customers(loc) extend using spatial_index(10e0, 100e0,
 1000e0)
create index storesx1 on stores(loc) extend using spatial_index(10e0, 100e0,
 1000e0)
create index storesx2 on stores(zone) extend using spatial_index(10e0, 100e0,
 1000e0)
 
insert into customers (cid, addr, loc) values (:cid, :addr, sdeFromBinary(:loc))
insert into customers (cid, addr, loc) values (:cid, :addr, geocode(:addr))
insert into stores (sid, addr, loc) values (:sid, :addr, sdeFromBinary(:loc))
 
update stores set zone = db2gse.ST_Buffer (loc, 2)
 
select cid, loc from customers
 where db2gse.ST_Within(loc, :polygon) = 1
 
select cid, loc from customers
 where db2gse.ST_Within(loc, :circle1) = 1 OR
       db2gse.ST_Within(loc, :circle2) = 1
 
select c.cid, loc from customers c, stores s
 where db2gse.ST_Contains(s.zone, c.loc) = 1 selectivity 0.01
 
select avg(c.income) from customers c
 where not exist (select * from stores s
                  where db2gse.ST_Distance(c.loc, s.loc) < 10)
 


[ ページのトップ | 前ページ | 次ページ | 目次 | 索引 ]