CG_ForceLHR — Force LHR orientation
geometry CG_ForceLHR(geometry geom);
Returns an equivalent geometry whose polygonal components follow the left-hand rule: exterior rings are counter-clockwise and interior rings are clockwise. Rings are reversed as needed; coordinates and dimensionality are preserved. The input must be valid.
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).
Reorient a polygon and its hole to the left-hand rule.
WITH data AS (
SELECT 'POLYGON((0 0,0 4,4 4,4 0,0 0),
(1 1,3 1,3 3,1 3,1 1))'::geometry AS geom
)
SELECT geom AS input_polygon,
CG_ForceLHR(geom) AS lhr_polygon,
ST_IsPolygonCCW(geom) AS input_is_lhr,
ST_IsPolygonCCW(CG_ForceLHR(geom)) AS output_is_lhr
FROM data;
POLYGON((0 0,0 4,4 4,4 0,0 0),(1 1,3 1,3 3,1 3,1 1)) | POLYGON((0 0,4 0,4 4,0 4,0 0),(1 1,1 3,3 3,3 1,1 1)) | f | t