ST_ForceRHR
What is ST_ForceRHR?
ST_ForceRHR orients polygon rings to follow the right-hand rule — exterior rings clockwise, interior rings counter-clockwise. It is equivalent to ST_ForcePolygonCW and predates that spelling.
ST_ForceRHR(geometry geom) → geometryNon-polygonal inputs pass through unchanged.
When would you use ST_ForceRHR?
Use ST_ForceRHR for compatibility with ESRI shapefile exporters and other legacy tools that expect the right-hand rule. It ensures polygons load with their fills on the correct side and interiors interpreted as holes rather than separate exteriors.
For GeoJSON RFC 7946 output, use ST_ForcePolygonCCW instead, since that format specifies the opposite convention.
FAQs
Is ST_ForceRHR the same as ST_ForcePolygonCW?
Effectively yes — both enforce CW exteriors with CCW holes. ST_ForcePolygonCW is the clearer modern spelling.
Why does GeoJSON need the opposite convention?
RFC 7946 adopted the OGC Simple Features convention (CCW exterior) to disambiguate polygons crossing the antimeridian. Shapefiles predate that convention and use the right-hand rule.
Does ST_ForceRHR affect linestrings or points?
No. Only polygonal rings are reoriented.
Is there a way to detect current orientation without reforcing?
Yes — ST_IsPolygonCW(geom) and ST_IsPolygonCCW(geom) return booleans you can filter or branch on.