CG_3DConvexHull — Computes the 3D convex hull of a geometry.
geometry CG_3DConvexHull(geometry geom1);
Computes the smallest convex three-dimensional geometry that contains the input. Unlike ST_ConvexHull, this function uses Z coordinates when constructing the hull.
Availability: 3.5.0
This method needs SFCGAL backend.
This function supports 3d and will not drop the z-index.
This function supports Polyhedral surfaces.
This function supports Triangles and Triangulated Irregular Network Surfaces (TIN).
Compute the 3D convex hull of a 3D LineString.
WITH data AS ( SELECT 'LINESTRING Z(0 0 5,1 5 3,5 7 6,9 5 3,5 7 5,6 3 5)'::geometry AS source_line ) SELECT CG_3DConvexHull(source_line) AS convex_hull FROM data;
POLYHEDRALSURFACE Z (((1 5 3,9 5 3,0 0 5,1 5 3)),((1 5 3,0 0 5,5 7 6,1 5 3)),((5 7 6,5 7 5,1 5 3,5 7 6)),((0 0 5,6 3 5,5 7 6,0 0 5)),((6 3 5,9 5 3,5 7 6,6 3 5)),((0 0 5,9 5 3,6 3 5,0 0 5)),((9 5 3,5 7 5,5 7 6,9 5 3)),((1 5 3,5 7 5,9 5 3,1 5 3)))
010F0000800800000001030000800100000004000000000000000000F03F00000000000014400000000000000840000000000000224000000000000014400000000000000840000000000000000000000000000000000000000000001440000000000000F03F0000000000001440000000000000084001030000800100000004000000000000000000F03F0000000000001440000000000000084000000000000000000000000000000000000000000000144000000000000014400000000000001C400000000000001840000000000000F03F000000000000144000000000000008400103000080010000000400000000000000000014400000000000001C40000000000000184000000000000014400000000000001C400000000000001440000000000000F03F0000000000001440000000000000084000000000000014400000000000001C4000000000000018400103000080010000000400000000000000000000000000000000000000000000000000144000000000000018400000000000000840000000000000144000000000000014400000000000001C4000000000000018400000000000000000000000000000000000000000000014400103000080010000000400000000000000000018400000000000000840000000000000144000000000000022400000000000001440000000000000084000000000000014400000000000001C400000000000001840000000000000184000000000000008400000000000001440010300008001000000040000000000000000000000000000000000000000000000000014400000000000002240000000000000144000000000000008400000000000001840000000000000084000000000000014400000000000000000000000000000000000000000000014400103000080010000000400000000000000000022400000000000001440000000000000084000000000000014400000000000001C40000000000000144000000000000014400000000000001C40000000000000184000000000000022400000000000001440000000000000084001030000800100000004000000000000000000F03F0000000000001440000000000000084000000000000014400000000000001C400000000000001440000000000000224000000000000014400000000000000840000000000000F03F00000000000014400000000000000840
Compare the extruded source geometry with its 3D convex hull.
WITH footprints(label, geom, height) AS (VALUES
('C', 'POLYGON((0 0,0 8,5 8,5 6,2 6,2 2,5 2,5 0,0 0))'::geometry, 3),
('H', 'POLYGON((7 0,9 0,9 3,12 3,12 0,14 0,14 8,12 8,12 5,9 5,9 8,7 8,7 0))'::geometry, 7)
), parts AS (
SELECT label, CG_Extrude(geom, 0, 0, height) AS geom
FROM footprints
), shapes AS (
SELECT ST_Collect(geom ORDER BY label) AS source_geometry
FROM parts
)
SELECT
source_geometry AS input_source_geometry,
CG_3DConvexHull(source_geometry) AS convex_hull
FROM shapes;
-[ RECORD 1 ]---------- input_source_geometry | GEOMETRYCOLLECTION(POLYHEDRALSURFACE(((0 0 0,0 8 0,5 8 0,5 6 0,2 6 0,2 2 0,5 2 0,5 0 0,0 0 0)),((0 0 3,5 0 3,5 2 3,2 2 3,2 6 3,5 6 3,5 8 3,0 8 3,0 0 3)),((0 0 0,0 0 3,0 8 3,0 8 0,0 0 0)),((0 8 0,0 8 3,5 8 3,5 8 0,0 8 0)),((5 8 0,5 8 3,5 6 3,5 6 0,5 8 0)),((5 6 0,5 6 3,2 6 3,2 6 0,5 6 0)),((2 6 0,2 6 3,2 2 3,2 2 0,2 6 0)),((2 2 0,2 2 3,5 2 3,5 2 0,2 2 0)),((5 2 0,5 2 3,5 0 3,5 0 0,5 2 0)),((5 0 0,5 0 3,0 0 3,0 0 0,5 0 0))), POLYHEDRALSURFACE(((7 0 0,7 8 0,9 8 0,9 5 0,12 5 0,12 8 0,14 8 0,14 0 0,12 0 0,12 3 0,9 3 0,9 0 0,7 0 0)),((7 0 7,9 0 7,9 3 7,12 3 7,12 0 7,14 0 7,14 8 7,12 8 7,12 5 7,9 5 7,9 8 7,7 8 7,7 0 7)),((7 0 0,7 0 7,7 8 7,7 8 0,7 0 0)),((7 8 0,7 8 7,9 8 7,9 8 0,7 8 0)),((9 8 0,9 8 7,9 5 7,9 5 0,9 8 0)),((9 5 0,9 5 7,12 5 7,12 5 0,9 5 0)),((12 5 0,12 5 7,12 8 7,12 8 0,12 5 0)),((12 8 0,12 8 7,14 8 7,14 8 0,12 8 0)),((14 8 0,14 8 7,14 0 7,14 0 0,14 8 0)),((14 0 0,14 0 7,12 0 7,12 0 0,14 0 0)),((12 0 0,12 0 7,12 3 7,12 3 0,12 0 0)),((12 3 0,12 3 7,9 3 7,9 3 0,12 3 0)),((9 3 0,9 3 7,9 0 7,9 0 0,9 3 0)),((9 0 0,9 0 7,7 0 7,7 0 0,9 0 0)))) convex_hull | POLYHEDRALSURFACE(((14 8 7,14 0 0,14 8 0,14 8 7)),((14 0 7,7 8 7,7 0 7,14 0 7)),((0 8 3,7 8 7,0 8 0,0 8 3)),((0 0 3,7 8 7,0 8 3,0 0 3)),((0 0 3,0 8 3,0 0 0,0 0 3)),((7 0 7,7 8 7,0 0 3,7 0 7)),((14 0 7,14 0 0,14 8 7,14 0 7)),((7 0 7,14 0 0,14 0 7,7 0 7)),((14 8 7,7 8 7,14 0 7,14 8 7)),((0 0 0,0 8 3,0 8 0,0 0 0)),((0 0 0,14 0 0,0 0 3,0 0 0)),((0 0 3,14 0 0,7 0 7,0 0 3)),((0 8 0,14 0 0,0 0 0,0 8 0)),((14 8 0,14 0 0,0 8 0,14 8 0)),((14 8 0,7 8 7,14 8 7,14 8 0)),((0 8 0,7 8 7,14 8 0,0 8 0)))
010700008002000000010F0000800A00000001030000800100000009000000000000000000000000000000000000000000000000000000000000000000000000000000000020400000000000000000000000000000144000000000000020400000000000000000000000000000144000000000000018400000000000000000000000000000004000000000000018400000000000000000000000000000004000000000000000400000000000000000000000000000144000000000000000400000000000000000000000000000144000000000000000000000000000000000000000000000000000000000000000000000000000000000010300008001000000090000000000000000000000000000000000000000000000000008400000000000001440000000000000000000000000000008400000000000001440000000000000004000000000000008400000000000000040000000000000004000000000000008400000000000000040000000000000184000000000000008400000000000001440000000000000184000000000000008400000000000001440000000000000204000000000000008400000000000000000000000000000204000000000000008400000000000000000000000000000000000000000000008400103000080010000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000084000000000000000000000000000002040000000000000084000000000000000000000000000002040000000000000000000000000000000000000000000000000000000000000000001030000800100000005000000000000000000000000000000000020400000000000000000000000000000000000000000000020400000000000000840000000000000144000000000000020400000000000000840000000000000144000000000000020400000000000000000000000000000000000000000000020400000000000000000010300008001000000050000000000000000001440000000000000204000000000000000000000000000001440000000000000204000000000000008400000000000001440000000000000184000000000000008400000000000001440000000000000184000000000000000000000000000001440000000000000204000000000000000000103000080010000000500000000000000000014400000000000001840000000000000000000000000000014400000000000001840000000000000084000000000000000400000000000001840000000000000084000000000000000400000000000001840000000000000000000000000000014400000000000001840000000000000000001030000800100000005000000000000000000004000000000000018400000000000000000000000000000004000000000000018400000000000000840000000000000004000000000000000400000000000000840000000000000004000000000000000400000000000000000000000000000004000000000000018400000000000000000010300008001000000050000000000000000000040000000000000004000000000000000000000000000000040000000000000004000000000000008400000000000001440000000000000004000000000000008400000000000001440000000000000004000000000000000000000000000000040000000000000004000000000000000000103000080010000000500000000000000000014400000000000000040000000000000000000000000000014400000000000000040000000000000084000000000000014400000000000000000000000000000084000000000000014400000000000000000000000000000000000000000000014400000000000000040000000000000000001030000800100000005000000000000000000144000000000000000000000000000000000000000000000144000000000000000000000000000000840000000000000000000000000000000000000000000000840000000000000000000000000000000000000000000000000000000000000144000000000000000000000000000000000010F0000800E0000000103000080010000000D0000000000000000001C40000000000000000000000000000000000000000000001C40000000000000204000000000000000000000000000002240000000000000204000000000000000000000000000002240000000000000144000000000000000000000000000002840000000000000144000000000000000000000000000002840000000000000204000000000000000000000000000002C40000000000000204000000000000000000000000000002C40000000000000000000000000000000000000000000002840000000000000000000000000000000000000000000002840000000000000084000000000000000000000000000002240000000000000084000000000000000000000000000002240000000000000000000000000000000000000000000001C40000000000000000000000000000000000103000080010000000D0000000000000000001C4000000000000000000000000000001C40000000000000224000000000000000000000000000001C40000000000000224000000000000008400000000000001C40000000000000284000000000000008400000000000001C40000000000000284000000000000000000000000000001C400000000000002C4000000000000000000000000000001C400000000000002C4000000000000020400000000000001C40000000000000284000000000000020400000000000001C40000000000000284000000000000014400000000000001C40000000000000224000000000000014400000000000001C40000000000000224000000000000020400000000000001C400000000000001C4000000000000020400000000000001C400000000000001C4000000000000000000000000000001C40010300008001000000050000000000000000001C40000000000000000000000000000000000000000000001C4000000000000000000000000000001C400000000000001C4000000000000020400000000000001C400000000000001C40000000000000204000000000000000000000000000001C4000000000000000000000000000000000010300008001000000050000000000000000001C40000000000000204000000000000000000000000000001C4000000000000020400000000000001C40000000000000224000000000000020400000000000001C400000000000002240000000000000204000000000000000000000000000001C400000000000002040000000000000000001030000800100000005000000000000000000224000000000000020400000000000000000000000000000224000000000000020400000000000001C40000000000000224000000000000014400000000000001C4000000000000022400000000000001440000000000000000000000000000022400000000000002040000000000000000001030000800100000005000000000000000000224000000000000014400000000000000000000000000000224000000000000014400000000000001C40000000000000284000000000000014400000000000001C4000000000000028400000000000001440000000000000000000000000000022400000000000001440000000000000000001030000800100000005000000000000000000284000000000000014400000000000000000000000000000284000000000000014400000000000001C40000000000000284000000000000020400000000000001C4000000000000028400000000000002040000000000000000000000000000028400000000000001440000000000000000001030000800100000005000000000000000000284000000000000020400000000000000000000000000000284000000000000020400000000000001C400000000000002C4000000000000020400000000000001C400000000000002C4000000000000020400000000000000000000000000000284000000000000020400000000000000000010300008001000000050000000000000000002C40000000000000204000000000000000000000000000002C4000000000000020400000000000001C400000000000002C4000000000000000000000000000001C400000000000002C40000000000000000000000000000000000000000000002C4000000000000020400000000000000000010300008001000000050000000000000000002C40000000000000000000000000000000000000000000002C4000000000000000000000000000001C40000000000000284000000000000000000000000000001C400000000000002840000000000000000000000000000000000000000000002C400000000000000000000000000000000001030000800100000005000000000000000000284000000000000000000000000000000000000000000000284000000000000000000000000000001C40000000000000284000000000000008400000000000001C4000000000000028400000000000000840000000000000000000000000000028400000000000000000000000000000000001030000800100000005000000000000000000284000000000000008400000000000000000000000000000284000000000000008400000000000001C40000000000000224000000000000008400000000000001C4000000000000022400000000000000840000000000000000000000000000028400000000000000840000000000000000001030000800100000005000000000000000000224000000000000008400000000000000000000000000000224000000000000008400000000000001C40000000000000224000000000000000000000000000001C4000000000000022400000000000000000000000000000000000000000000022400000000000000840000000000000000001030000800100000005000000000000000000224000000000000000000000000000000000000000000000224000000000000000000000000000001C400000000000001C4000000000000000000000000000001C400000000000001C4000000000000000000000000000000000000000000000224000000000000000000000000000000000 | 010F00008010000000010300008001000000040000000000000000002C4000000000000020400000000000001C400000000000002C40000000000000000000000000000000000000000000002C40000000000000204000000000000000000000000000002C4000000000000020400000000000001C40010300008001000000040000000000000000002C4000000000000000000000000000001C400000000000001C4000000000000020400000000000001C400000000000001C4000000000000000000000000000001C400000000000002C4000000000000000000000000000001C40010300008001000000040000000000000000000000000000000000204000000000000008400000000000001C4000000000000020400000000000001C40000000000000000000000000000020400000000000000000000000000000000000000000000020400000000000000840010300008001000000040000000000000000000000000000000000000000000000000008400000000000001C4000000000000020400000000000001C4000000000000000000000000000002040000000000000084000000000000000000000000000000000000000000000084001030000800100000004000000000000000000000000000000000000000000000000000840000000000000000000000000000020400000000000000840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840010300008001000000040000000000000000001C4000000000000000000000000000001C400000000000001C4000000000000020400000000000001C400000000000000000000000000000000000000000000008400000000000001C4000000000000000000000000000001C40010300008001000000040000000000000000002C4000000000000000000000000000001C400000000000002C40000000000000000000000000000000000000000000002C4000000000000020400000000000001C400000000000002C4000000000000000000000000000001C40010300008001000000040000000000000000001C4000000000000000000000000000001C400000000000002C40000000000000000000000000000000000000000000002C4000000000000000000000000000001C400000000000001C4000000000000000000000000000001C40010300008001000000040000000000000000002C4000000000000020400000000000001C400000000000001C4000000000000020400000000000001C400000000000002C4000000000000000000000000000001C400000000000002C4000000000000020400000000000001C4001030000800100000004000000000000000000000000000000000000000000000000000000000000000000000000000000000020400000000000000840000000000000000000000000000020400000000000000000000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000000000000000000002C4000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000000000000000000000000000000010300008001000000040000000000000000000000000000000000000000000000000008400000000000002C40000000000000000000000000000000000000000000001C4000000000000000000000000000001C40000000000000000000000000000000000000000000000840010300008001000000040000000000000000000000000000000000204000000000000000000000000000002C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020400000000000000000010300008001000000040000000000000000002C40000000000000204000000000000000000000000000002C40000000000000000000000000000000000000000000000000000000000000204000000000000000000000000000002C4000000000000020400000000000000000010300008001000000040000000000000000002C40000000000000204000000000000000000000000000001C4000000000000020400000000000001C400000000000002C4000000000000020400000000000001C400000000000002C4000000000000020400000000000000000010300008001000000040000000000000000000000000000000000204000000000000000000000000000001C4000000000000020400000000000001C400000000000002C4000000000000020400000000000000000000000000000000000000000000020400000000000000000