@mapbox/geojson-rewind
Enforce the right-hand-rule polygon ring winding order for GeoJSON geometries.
Repository Health
Technical Analysis
@mapbox/geojson-rewind fixes the winding order of Polygon and MultiPolygon rings so that GeoJSON geometries comply with the RFC 7946 specification, which requires exterior rings to be counterclockwise and interior rings (holes) to be clockwise. Many data sources produce rings in the wrong order, and this tiny library rewrites them in place.
Beyond spec compliance, correct winding order lets Canvas and other drawing libraries use their default even-odd fill behavior to render polygon holes correctly. The package works as both an importable function and a command-line filter, making it easy to drop into data pipelines and build steps.
What You Get
- A single
rewind(geojson, clockwise?)function that normalizes Polygon and MultiPolygon winding order - RFC 7946-compliant output by default, with an option for the inverse convention
- A command-line interface that rewinds GeoJSON piped through stdin
- A dependency-light implementation suitable for build steps and data pipelines
Common Use Cases
- Making third-party or user-supplied GeoJSON valid before storing or serving it
- Fixing polygon fills so holes render correctly in Canvas and WebGL map layers
- Normalizing geometry winding order in ETL and tiling pipelines
Under The Hood
Architecture
The whole library is a single index.js exporting a rewind function that walks a GeoJSON object’s geometry tree, and for each Polygon/MultiPolygon reorders ring coordinates by computing signed ring area and reversing rings whose orientation is wrong. A small companion geojson-rewind bin script wraps the same function as a stdin/stdout CLI filter.
Tech Stack
Plain JavaScript with no runtime dependencies for the core algorithm; the CLI wrapper pulls in get-stream and minimist for stdin reading and argument parsing. Distributed as a CommonJS module.
Code Quality
Despite its age the repo is small and focused, with a test/ directory of fixture-based tests and CODEOWNERS governance from Mapbox. The single-purpose design keeps the surface area and failure modes minimal.
API Design
The API is about as simple as it gets: import one function, pass a GeoJSON object, get a corrected object back. The optional boolean for winding convention is the only knob, and the dual library/CLI packaging means it slots into both code and shell pipelines with almost no learning curve.