简介
栅格数据由按行和列(或格网)组织的像元(或像素)矩阵组成,其中的每个像元都包含一个信息值(例如温度)。
栅格数据可以是数字航空像片、卫星影像、数字图片或扫描的地图。
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参考。