名稱

ST_ConvexHull — 傳回柵格的凸包幾何,包含數值等於 BandNoDataValue 的像素。對於規則形狀且未傾斜的柵格,這會產生與 ST_Envelope 相同的結果,因此僅適用於不規則形狀或傾斜的柵格。

概要

geometry ST_ConvexHull(raster rast);

描述

傳回柵格的凸包幾何,包含 NoDataBandValue 頻段的像素。對於規則形狀且未傾斜的柵格,這會產生與 ST_Envelope 大致相同的結果,因此僅適用於不規則形狀或傾斜的柵格。

[Note]

ST_Envelope 會將座標向下取整,因此會在柵格周圍增加一些緩衝區,所以結果與不向下取整的 ST_ConvexHull 略有不同。

範例

請參閱PostGIS 柵格規範以查看此圖表。

-- Note envelope and convexhull are more or less the same
SELECT ST_AsText(ST_ConvexHull(rast)) As convhull,
    ST_AsText(ST_Envelope(rast)) As env
FROM dummy_rast WHERE rid=1;

                        convhull                        |                env
--------------------------------------------------------+------------------------------------
 POLYGON((0.5 0.5,20.5 0.5,20.5 60.5,0.5 60.5,0.5 0.5)) | POLYGON((0 0,20 0,20 60,0 60,0 0))
                
-- now we skew the raster
-- note how the convex hull and envelope are now different
SELECT ST_AsText(ST_ConvexHull(rast)) As convhull,
    ST_AsText(ST_Envelope(rast)) As env
FROM (SELECT ST_SetRotation(rast, 0.1, 0.1) As rast
    FROM dummy_rast WHERE rid=1) As foo;

                        convhull                        |                env
--------------------------------------------------------+------------------------------------
 POLYGON((0.5 0.5,20.5 1.5,22.5 61.5,2.5 60.5,0.5 0.5)) | POLYGON((0 0,22 0,22 61,0 61,0 0))