ST_Polygon — NODATA値でないピクセル値を持つピクセルの結合で形成されるポリゴンジオメトリを返します。バンド番号を設定しない場合には、デフォルトは1番バンドです。
geometry ST_Polygon(
raster rast, integer band_num=1)
;
-- デフォルトではNODATA値は0になるか設定されていないので -- ポリゴンは四角形のポリゴンとなります SELECT ST_AsText(ST_Polygon(rast)) As geomwkt FROM dummy_rast WHERE rid = 2; geomwkt -------------------------------------------- POLYGON((3427927.8 5793243.75,3427927.75 5793243.75,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9, 3427927.75 5793244,3427927.8 5793244,3427927.85 5793244,3427927.9 5793244,3427928 5793244,3427928 5793243.95, 3427928 5793243.85,3427928 5793243.8,3427928 5793243.75,3427927.85 5793243.75,3427927.8 5793243.75)) -- 1番バンドのNODATA値を変更します UPDATE dummy_rast SET rast = ST_SetBandNoDataValue(rast,1,254) WHERE rid = 2; SELECt rid, ST_BandNoDataValue(rast) from dummy_rast where rid = 2; -- ST_Polygonピクセル値が254のピクセルを除外してマルチポリゴンを返します SELECT ST_AsText(ST_Polygon(rast)) As geomwkt FROM dummy_rast WHERE rid = 2; geomwkt --------------------------------------------------------- MULTIPOLYGON(((3427927.9 5793243.95,3427927.85 5793243.95,3427927.85 5793244,3427927.9 5793244,3427927.9 5793243.95)), ((3427928 5793243.85,3427928 5793243.8,3427927.95 5793243.8,3427927.95 5793243.85,3427927.9 5793243.85,3427927.9 5793243.9,3427927.9 5793243.95,3427927.95 5793243.95,3427928 5793243.95,3427928 5793243.85)), ((3427927.8 5793243.75,3427927.75 5793243.75,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9,3427927.75 5793244,3427927.8 5793244, 3427927.8 5793243.9,3427927.8 5793243.85,3427927.85 5793243.85,3427927.85 5793243.8,3427927.85 5793243.75,3427927.8 5793243.75))) -- 1回だけ違うNODATA値にしてみます SELECT ST_AsText( ST_Polygon( ST_SetBandNoDataValue(rast,1,252) ) ) As geomwkt FROM dummy_rast WHERE rid =2; geomwkt --------------------------------- POLYGON((3427928 5793243.85,3427928 5793243.8,3427928 5793243.75,3427927.85 5793243.75,3427927.8 5793243.75,3427927.8 5793243.8,3427927.75 5793243.8,3427927.75 5793243.85,3427927.75 5793243.9,3427927.75 5793244,3427927.8 5793244,3427927.85 5793244,3427927.9 5793244,3427928 5793244,3427928 5793243.95,3427928 5793243.85), (3427927.9 5793243.9,3427927.9 5793243.85,3427927.95 5793243.85,3427927.95 5793243.9,3427927.9 5793243.9))