40

http://geojsonlint.com/ I get error

 Polygons and MultiPolygons should follow the right-hand rule

I used it for past 3 years without any problem with my old GeoJSON file. Now geojsonlint enforce the right hand rule, how to fix the problem.


Updated in July 2022

So what is right hand rule for polygon in GeoJSON format?

polygon definition, click here

enter image description here

A good example of create 4 point rectangle viewport bbox bounding box use GeoJSON

enter image description here

1
  • Hi OP, can you mark an answer as accepted pls?
    – Nikhil VJ
    Commented Jul 10, 2021 at 2:12

6 Answers 6

17

The Right Hand Rule GeoJSON Fixer | Mapster page has a client-side JavaScript function that fixes the right hand rule problem.

4
  • This service isn't working anymore, in FF or Chrome
    – Henrik
    Commented Mar 19, 2019 at 18:49
  • @Henrik : I've just used it working correctly in FF.70. Maybe it's back.
    – allez l'OM
    Commented Dec 3, 2019 at 12:02
  • 2
    Hi it is working correctly, if you would like to do it yourself you can checkout github.com/mapbox/geojson-rewind / npmjs.com/package/@mapbox/geojson-rewind Commented Nov 8, 2020 at 20:21
  • 1
    Good to know, that page is essentially calling ogr2ogr -f GeoJSON -lco RFC7946=YES output.json input.json
    – Akaisteph7
    Commented Sep 11 at 18:27
12

For anyone finding this and looking for a tool to fix them. GDALs ogr2ogr can take "2008" spec GeoJSON and write out in "RFC7946" standard mode (with polygons following the right-hand rule for orientation).

ogr2ogr -f GeoJSON -lco RFC7946=YES output.json input.json

or for use in scripts where you want to input and output the GeoJSON as a string:

echo 'Your GeoJSON' | ogr2ogr -f GeoJSON -lco RFC7946=YES /vsistdout/ /vsistdin/

10

As of August 2016 GeoJSON is now a formal IETF specification. And some things have changed from the old informal 2008 spec. So to be valid for the 2016 spec your polygons MUST be right-hand wound.

See https://www.rfc-editor.org/rfc/rfc7946#section-3.1.6

The use of MUST indicates an absolute requirement of the specification. However then the subsequent language about not rejecting other windings is weird and is open to some argument - perhaps parsers should accept and correct other windings. I think this what lead geojsonlint (from geojsonhint) to use the word should instead of MUST in their feedback message.

So I agree with the position of geojsonlint.com as they place right at the top of their page the link to the 2016 spec. Your polygons are bad per the 2016 spec. But yet they are fine per the informal 2008 spec. So if you do not wish to change the winding of your polygons, you will need to make certain any linters or parsers you use honor the old 2008 spec and do not one day suddenly migrate to the new formal spec.

Or perhaps you should consider changing your polygon winding as doing so will get you in line with both specs and better positioned for the future as the 2008 spec fades away.

Note that for me the largest change in the 2016 spec was the dropping utterly of the support for coordinate systems. I had all my GeoJSON in NAD83 and then had to quietly remove that as now all GeoJSON is WGS84. Fortunately for me coming from Oracle Spatial all my polygons were already right-hand wound.

3
  • For me it would be good if geojsonlint had on option to skip the winding test, or report that as a separate issue. That is what the specification is somehow recommending as well.
    – user30184
    Commented Oct 28, 2017 at 12:59
  • My polygons were generated by postgis ST_AsGeoJSON function and are bad too.
    – Magno C
    Commented Nov 16, 2020 at 6:11
  • 1
    I had the problem @MagnoC described. This answer helped me gis.stackexchange.com/questions/306567/… In short, wrap the value passed to ST_AsGeoJSON in ST_ForcePolygonCCW Commented Aug 5, 2021 at 21:07
9

Click here for what is right hand rule

My old GeoJSON worked with Google Maps, Leaflet, OpenLayers, Mapbox, Bing Maps, etc. however failed geojsonlint.com validate.

I have to use another website to validate: http://geojson.io

6

This can be fixed very easily in Python using geojson-rewind.

from geojson_rewind import rewind

rewoundGeoJSON = rewind(geoJSONString)
3

I'm a bit late to the party, but geojsonlint uses a buggy version of geojsonhint (the underlying validator).

geojsonhint attempts to validate ring orientations by calculating negative / positive area, but does so incorrectly.

In other words, the validation error from the site cannot be trusted at this point in time. Note also that, as of May 2024, the geojsonhint repo has been archived.

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.