ST_MinConvexHull — Return the convex hull geometry of the raster excluding NODATA pixels.
geometry ST_MinConvexHull(raster rast, integer nband=NULL);
Return the convex hull geometry of the raster excluding NODATA pixels. If nband is NULL, all bands of the raster are considered.
Availability: 2.1.0
WITH foo AS (
SELECT
ST_SetValues(ST_SetValues(ST_AddBand(ST_AddBand(ST_MakeEmptyRaster(9, 9, 0, 0, 1, -1, 0, 0, 0), 1, '8BUI', 0, 0), 2, '8BUI', 1, 0),
1, 1, 1,
ARRAY[
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 1],
[0, 0, 0, 1, 1, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0]
]::double precision[][]
),
2, 1, 1,
ARRAY[
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 0, 0, 0, 0]
]::double precision[][]
) AS rast
)
SELECT title, geom AS geom
FROM foo
CROSS JOIN LATERAL (VALUES
('raster hull', ST_ConvexHull(rast)),
('all bands', ST_MinConvexHull(rast)),
('band 1', ST_MinConvexHull(rast, 1)),
('band 2', ST_MinConvexHull(rast, 2))
) AS variants(title, geom);
title | geom -------------+--------------------------------------- raster hull | POLYGON((0 0,9 0,9 -9,0 -9,0 0)) all bands | POLYGON((0 -3,9 -3,9 -9,0 -9,0 -3)) band 1 | POLYGON((3 -3,9 -3,9 -6,3 -6,3 -3)) band 2 | POLYGON((0 -3,6 -3,6 -9,0 -9,0 -3))