ST_IsPolygonCW
What is ST_IsPolygonCW?
ST_IsPolygonCW is a PostGIS function that returns true when a polygon's exterior ring is clockwise and its interior rings are counter-clockwise — the orientation convention used by Esri Shapefile and some other legacy formats.
ST_IsPolygonCW(geometry g) → booleanWorks on POLYGON and MULTIPOLYGON.
When would you use ST_IsPolygonCW?
Use ST_IsPolygonCW when exporting to Shapefile or any system that expects CW exterior rings, or when validating legacy imports. Flip when necessary with ST_ForcePolygonCW:
1SELECT id,
2 CASE WHEN NOT ST_IsPolygonCW(geom)
3 THEN ST_ForcePolygonCW(geom)
4 ELSE geom
5 END AS shp_ready_geom
6FROM parcels;FAQs
Which formats expect CW orientation?
Shapefile is the most prominent. Some raster-vector engines also assume CW. GeoJSON (RFC 7946) requires CCW, so always check your target format.
Can a polygon be neither CW nor CCW?
In principle no — every valid ring has an orientation. In practice, zero-area collapsed rings or self-intersecting rings may return ambiguous results; those are also invalid per ST_IsValid.
Does ST_IsPolygonCW return NULL for non-polygons?
Yes. Filter with a GeometryType check first if you need a non-null boolean.
Is this a validity check?
No — orientation is independent of validity. Use ST_IsValid to check topological correctness.