CG_3DConvexHull
Name
CG_3DConvexHull — Computes the 3D convex hull of a geometry.
Synopsis
geometry
CG_3DConvexHull
(
geometry
geom1
)
;
Description
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).
Examples
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)))
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;