全部產品
Search
文件中心

AnalyticDB:柵格模型

更新時間:Feb 05, 2024

簡介

柵格資料由按行和列(或格網)組織的像元(或像素)矩陣組成,其中的每個像元都包含一個資訊值(例如溫度)。

柵格資料可以是數字航空像片、衛星影像、數字圖片或掃描的地圖。

Ganos時空引擎通過在ADB PG中實現柵格資料模型,可以藉助於資料庫的技術和方法高效地對柵格資料進行儲存和分析操作。

快速入門

  • 建立擴充
    Create extension ganos_spatialref;
    Create extension ganos_geometry;
    Create Extension Ganos_Raster;
  • 建立柵格表
    -- 指定raster 列作為表的 distributed column
    Create Table raster_table(id integer, raster_obj raster) 
    DISTRIBUTED BY (raster_obj);
  • 從OSS中匯入柵格資料
    Insert into raster_table 
    Values(1, ST_ImportFrom('chunk_table','OSS://<id>:<key>@oss-cn.aliyuncs.com/mybucket/data/my_image.tif')),
    (2, ST_CreateRast('OSS://<id>:<key>@oss-cn.aliyuncs.com/mybucket/data/my_image.tif'));
  • 查詢柵格對象資訊
    Select ST_Height(raster_obj),ST_Width(raster_obj) From raster_table Where id = 1;
     st_height 
    -----------
          1241
    (1 rows)
  • 建立金字塔
    DO $$
    declare
        rast raster;
    begin
        select raster_obj into rast from raster_table where id = 1;
        rast = st_buildpyramid(rast);
        update raster_table set raster_obj = rast where id = 1;
    end;    
    $$ LANGUAGE 'plpgsql';
    
    DO $$
    declare
        rast raster;
    begin
        select raster_obj into rast from raster_table where id = 2;
        rast = st_buildpyramid(rast, -1, 'Near', 'chunk_table');
        update raster_table set raster_obj = rast where id = 2;
    end;    
    $$ LANGUAGE 'plpgsql';
  • 根據視口的全局座標範圍,長和寬來計算最佳的金字塔層級
    Select ST_BestPyramidLevel(rast, '((128.0, 30.0),(128.5, 30.5))', 800, 600) from raster_table where id = 1;
    
    ---------------------
    3
  • 擷取柵格指定範圍像素矩陣
    DO $$
    declare
        rast raster;
    begin
        select raster_obj into rast from raster_table where id = 1;
        rast = st_buildpyramid(rast);
        Select ST_Clip(rast, 0, '((128.980,30.0),(129.0,30.2))', 'World');
    end;    
    $$ LANGUAGE 'plpgsql';
  • 計算裁剪的像素座標範圍
    Select ST_ClipDimension(raster_obj, 2, '((128.0, 30.0),(128.5, 30.5))') 
    from raster_table where id = 1;
    
    ------------------------------------
    '((600, 720),(200, 300))'
  • 刪除擴充
    DROP Extension Ganos_Raster;
    DROP extension ganos_geometry;
    DROP extension ganos_spatialref;

SQL參考

詳細SQL參考請參見Raster SQL參考