PostGISGeometry Accessors

ST_IsPolygonCCW

What is ST_IsPolygonCCW?

ST_IsPolygonCCW is a PostGIS function that returns true when a polygon's exterior ring is oriented counter-clockwise and its interior rings (holes) are oriented clockwise — the orientation convention used by GeoJSON and many modern formats.

SQL
ST_IsPolygonCCW(geometry g)boolean

Works on POLYGON and MULTIPOLYGON; true is returned only when every polygon satisfies the CCW outer / CW inner rule.

When would you use ST_IsPolygonCCW?

Use ST_IsPolygonCCW when exporting to formats or engines that require CCW orientation (GeoJSON RFC 7946, many map libraries, some topology libraries), or when validating after imports:

SQL
1SELECT id, geom
2FROM imported_polygons
3WHERE NOT ST_IsPolygonCCW(geom);
4-- flip with ST_ForcePolygonCCW on the result set

Repair ordering with ST_ForcePolygonCCW; the inverse is ST_ForcePolygonCW.

FAQs

Why does orientation matter?

The right-hand rule defines which side of the ring is "inside". Some rendering libraries and topology engines rely on consistent CCW orientation to determine fill. Shapefiles conventionally store CW exterior; GeoJSON expects CCW.

What does ST_IsPolygonCCW return for non-Polygon input?

NULL for types other than POLYGON or MULTIPOLYGON. Filter input types if you need a strict boolean.

Is this related to validity?

No. A CW polygon is still valid per OGC. Orientation is a separate property checked by ST_IsPolygonCCW/ST_IsPolygonCW.

How do I normalize all polygons to CCW?

UPDATE table SET geom = ST_ForcePolygonCCW(geom) WHERE NOT ST_IsPolygonCCW(geom); — only update rows that need it to avoid unnecessary writes.