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?


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 Dec 19 '18 at 19:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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