CG_GenerateSkillionRoof
Name
CG_GenerateSkillionRoof — Generate a skillion (single-slope) roof from a footprint polygon.
Synopsis
geometry
CG_GenerateSkillionRoof
(
geometry
geom
, float8
height
, float8
slope_angle
, integer
primary_edge_index
)
;
Description
Generate a skillion (single-slope, shed-style) roof as a 3D
PolyhedralSurface Z
from a 2D footprint polygon.
The entire roof surface slopes in one direction.
height
sets the maximum ridge height (default 3.0),
slope_angle
sets the pitch in degrees (default
30.0), and
primary_edge_index
selects which
polygon edge defines the high side (0-based, default 0).
When the combination of
height
and
slope_angle
would cause a side wall to vanish
(the slope reaches the far edge before the full height is achieved),
that face is omitted from the result. This means the number of
output patches can vary depending on the parameters — a lower
height relative to the footprint depth produces more faces than
a taller, steeper configuration.
Availability: 3.7.0 - requires SFCGAL >= 2.3.0.
This method needs SFCGAL backend.
This function supports Polyhedral surfaces.
Examples
Height 2.0 produces 6 faces (all walls present); height 4.0 produces 5 faces (one side wall is filtered out because the slope reaches the far edge before the full height).
SELECT
ST_NumPatches(CG_GenerateSkillionRoof(
'POLYGON((0 0,5 0,5 4,0 4,0 0))', 2.0)) AS "height 2",
ST_NumPatches(CG_GenerateSkillionRoof(
'POLYGON((0 0,5 0,5 4,0 4,0 0))', 4.0)) AS "height 4";
6 | 5
The height 2.0 result is shown with its footprint.
WITH data AS ( SELECT 'POLYGON((0 0,5 0,5 4,0 4,0 0))'::geometry AS footprint ) SELECT CG_GenerateSkillionRoof(footprint, 2.0) AS roof FROM data;
POLYHEDRALSURFACE Z (((0 4 0,5 4 0,5 0 0,0 0 0,0 4 0)),((5 0 2,5 4 2,3.464 4 2,3.464 0 2,5 0 2)),((0 4 0,0 0 0,3.464 0 2,3.464 4 2,0 4 0)),((0 0 0,5 0 0,5 0 2,3.464 0 2,0 0 0)),((5 0 0,5 4 0,5 4 2,5 0 2,5 0 0)),((5 4 0,0 4 0,3.464 4 2,5 4 2,5 4 0)))