4.1 GeoRasterオブジェクトの問合せと検索

GeoRaster表は、ID番号、名前、タイムスタンプ、文字列形式での独自の説明など、様々な列を持つことのできる通常のリレーショナル表です。これらの列には索引を付けることができ、GeoRasterオブジェクトは、このマニュアルの多くの例で示しているとおり、標準的なデータベースの索引付けおよび問合せの文を使用して問い合せることが可能です。

GeoRaster表に空間索引が付けられると(「GeoRasterオブジェクトの索引付け」を参照)、ジオメトリも使用してGeoRasterオブジェクトの問合せまたは検索を迅速に行うことができます。たとえば、次の例に示すとおり、特定の地域内のすべてのイメージ(通常は数百以上)を検出して、イメージごとに完全なピラミッドを生成できます。

例4-1 GeoRasterオブジェクトの検索およびそれらのピラミッドの生成

DECLARE
  type curtype is ref cursor;
  my_cursor curtype;
  stmt varchar2(1000);
  tid     number;
  gr    sdo_georaster;
  gm  sdo_geometry;
BEGIN
  -- 1. Define the query area in EPSG 4326 (WGS84) coordinate system
  gm := sdo_geometry(2003, 4326, null,
              sdo_elem_info_array(1,1003,3),
              sdo_ordinate_array(5,6,30,30));
 
  -- 2. Define the query statement on the GeoRaster table (city_images)using the given geometry
  stmt := 'select id from city_images t ' ||
    'where sdo_inside(t.image.spatialextent, :1)=''TRUE''';
 
  -- 3. Spatially query all images INSIDE the query area 
  --    and generate full pyramids for each of the images
  open my_cursor for stmt using gm;
  loop
    fetch my_cursor into tid;
    exit when my_cursor%NOTFOUND;
    -- retrieve the image to generate the pyramids
    select image into gr from city_images where id = tid for update;
    sdo_geor.generatePyramid(gr, 'resampling=bilinear', null, ‘parallel=4’);
    update city_images set image=gr
       where id = tid;
    commit; 
  end loop;
  close my_cursor;
END;

このようなブロックをPL/SQLプロシージャにまとめてデータベースに格納し、そのストアド・プロシージャを直接コールすることもできます。これらの機能によって、複雑なプロセスを編成し、データベース管理タスクを自動化できます。