I am using the following query to create a GeoJson response:

SELECT json_build_object(
    'type',         'FeatureCollection',
    'features',     jsonb_agg(feature)
    SELECT json_build_object(
        'type',         'Feature',
        'id',           id,
        'geometry',     ST_AsGeoJSON(ST_ForcePolygonCW(wkb_geometry))::json,
        'properties',   to_jsonb(row) - 'id' - 'wkb_geometry'
    ) AS feature
    FROM (SELECT * FROM gis_states LIMIT 1) AS row
) AS features

The resulting data-set (https://pastebin.com/hvFQXUTr) does not validate at http://geojsonlint.com, even though I am using ST_ForcePolygonCW:

Line 1: Polygons and MultiPolygons should follow the right-hand rule

Any suggestions on how to fix this?


1 Answer 1


OK, so the documentation (https://postgis.net/docs/ST_ForceRHR.html) states that ST_ForcePolygonCW is a synonym of ST_ForceRHR(). However, I wonder if the linter at http://geojsonlint.com/ is working properly, or perhaps the error is too ambiguous, as I got it to render correctly by using ST_ForcePolygonCCW, which is the opposite.

  • 2
    The problem is that "Right-Hand-Rule" isn't a very useful term in GIS. Some GIS software (e.g., PostGIS) uses it to refer mean that the interior of a boundary is to your right as you walk around it (clockwise orientation). In most other contexts, it refers to the direction your fingers curl when the thumb of your right hand is pointing towards your head (counterclockwise orientation).
    – dbaston
    Commented Dec 19, 2018 at 19:04
  • 1
    This answer was very helpful, thanks. Multiple linters confirm ST_ForcePolygonCCW produces valid output for GeoJSON
    – agmin
    Commented Sep 1, 2021 at 0:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.