Awesome
rfc7946-to-d3
Converts polygon winding order between RFC7946 geojson and D3 compatible conventions.
Why
D3 assumes GeoJSON polygon coordinates to be sorted in a clockwise order, while rfc7946 GeoJSON assumes the opposite (counterclockwise or right-hand-rule winding). This difference causes issues for example when calculating bounding boxes or applying projections on such polygons.
This module converts between the two convertions by simply reversing the order of all (multi)polygon linear rings of the given input.
Usage
- as npm module
install:
npm install --save rfc7946-to-d3
api:
A function that takes in rfc7946 geojson and spits out d3 compatible geojson (input is modified in place!).
- as cli utility
install:
[sudo] npm install -g rfc7946-to-d3
use:
rfc7946-to-d3 < rfc7946.geojson > d3.geojson
See also
- geojson-rewind a module that enforces geojson polygon ring winding order. (Useful when working with legacy geojson data: e.g.
cat legacy.geojson | geojson-rewing | rfc7946-to-d3 | geoproject …
)