ST_ForcePolygonCW
What is ST_ForcePolygonCW?
ST_ForcePolygonCW reorients polygon rings so that exterior rings are clockwise (CW) and interior rings (holes) are counter-clockwise (CCW).
ST_ForcePolygonCW(geometry geom) → geometryThis is the shapefile and ESRI convention. Non-polygonal inputs are returned unchanged.
When would you use ST_ForcePolygonCW?
Use ST_ForcePolygonCW before writing to ESRI shapefiles or other formats that follow the right-hand-rule convention with CW exteriors. It avoids shape-file loaders rejecting polygons or, worse, treating them as holes. Pair it with format-specific export tooling so the on-disk result is unambiguous.
When copying features between systems with different winding conventions, explicitly forcing CW or CCW is a robust way to normalize orientation before further processing.
FAQs
What is the opposite of ST_ForcePolygonCW?
ST_ForcePolygonCCW — it produces CCW exteriors with CW holes (the OGC and GeoJSON convention).
Is ST_ForcePolygonCW the same as ST_ForceRHR?
Effectively yes — both enforce the right-hand rule with CW exterior rings. ST_ForceRHR is the older spelling; ST_ForcePolygonCW is the clearer modern name.
Will it modify non-polygon geometry?
No. Points, lines, and non-polygon collection members are returned unchanged.
How do I check a polygon's current orientation?
Use ST_IsPolygonCW(geom) or the inverse ST_IsPolygonCCW(geom). They return booleans for polygons and MultiPolygons.