geojsonkit.org
GeoJSON utilities, in the browser
Say hi →

GeoJSON winding order

RFC 7946 says a polygon's exterior ring must wind counter-clockwise and its holes clockwise. Plenty of software ignores that, and a few consumers — notably MongoDB and some tile pipelines — reject or invert the result. This rewinds every ring, and closes any that were left open.

GeoJSON winding order

updated 20 August 2026

Drop a .geojson file, or

What this tool does

It checks the direction of every polygon ring and reverses the ones pointing the wrong way. The rule in RFC 7946 §3.1.6 is the right-hand rule: exterior rings counter-clockwise, interior rings (holes) clockwise. The status line reports how many rings were checked and how many were flipped, so you can tell whether the file was already conformant.

The intent it closes: "my polygons render inside-out, or the database refuses them." MongoDB's 2dsphere index treats a clockwise exterior ring as covering the rest of the planet; some vector-tile and canvas renderers use winding for fill rules; and a shapefile converted with older tools almost always comes out clockwise, because that is the shapefile convention.

How this tool works

Ring by ring, with a signed-area test.

1. Close the ring if needed

A linear ring must repeat its first position at the end. With close open rings on, a ring whose last position differs from its first has the first appended — done before the direction test, since an unclosed ring gives a misleading signed area.

2. Test the direction

The ring's orientation comes from the sign of its shoelace sum over consecutive vertex pairs — positive for clockwise in the standard longitude/latitude arrangement. Rings with fewer than four positions are left alone; they are degenerate and reversing them would not help.

3. Reverse what is wrong

For the RFC order, the first ring of each polygon must be counter-clockwise and every following ring clockwise; the legacy option is the exact mirror. Rings that already point the right way are untouched, so the output stays as close to the input as possible. MultiPolygon parts are handled independently, and geometries inside a GeometryCollection are visited recursively.

Options

Winding

RFC 7946 is what you want for anything modern: the spec, MongoDB, and current tooling all expect exterior counter-clockwise. Legacy produces the opposite — exterior clockwise, holes counter-clockwise — which is the shapefile and older-Esri convention, and is occasionally what a downstream system insists on.

close open rings

Leave it on. An unclosed ring is invalid GeoJSON and a common export bug; closing it is a one-position fix that costs nothing. Turn it off only if you specifically want to see which rings were open, in which case the validator reports them.

Example

Input (exterior ring clockwise):

{ "type": "Polygon", "coordinates": [
  [[0,0],[0,2],[4,2],[4,0],[0,0]]
] }

Output (RFC 7946 — reversed to counter-clockwise):

{
  "type": "FeatureCollection",
  "features": [
    { "type": "Feature", "properties": {}, "geometry": { "type": "Polygon",
      "coordinates": [[[0, 0], [4, 0], [4, 2], [0, 2], [0, 0]]] } }
  ]
}

The same four corners, listed the other way round. The status bar reads 1 ring(s) checked · 1 reversed. Nothing about the shape changed — only the direction of travel, which is what the spec constrains.

Tips & common pitfalls

  • Winding is not validity. A wrongly wound polygon is still a well-formed shape; a self-intersecting one is not. This tool fixes direction only — use the validator for structural problems.
  • MongoDB is the usual reason. With a 2dsphere index, a clockwise exterior ring means "everything except this shape", which is why a query suddenly matches the whole world.
  • Shapefile conversions are usually clockwise. If your data came from a .shp, expect most exterior rings to need reversing.
  • Rewinding is safe to re-run. Rings already in the target order are left untouched, so running it twice changes nothing the second time.

FAQ

Does winding order really matter?

For rendering in most web maps, no. For MongoDB's 2dsphere index, some vector-tile builders, and strict RFC 7946 consumers, yes — and it is the difference between a polygon and its complement.

Which direction does RFC 7946 require?

Exterior rings counter-clockwise, interior rings clockwise, following the right-hand rule (§3.1.6). Note that the earlier 2008 GeoJSON specification said nothing about it, which is why so much data is inconsistent.

Are points and lines affected?

No. Only polygon rings have a winding order; every other geometry type passes through unchanged.

What about the antimeridian?

Winding is computed from the coordinates as given. A polygon that crosses ±180° without being split has an ambiguous orientation — split it first, as RFC 7946 §3.1.9 recommends.