Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
@mapbox/geojson-rewind
Advanced tools
@mapbox/geojson-rewind is an npm package that allows you to reorient the winding order of GeoJSON polygons to ensure they follow the right-hand rule. This is useful for ensuring compatibility with various GIS systems and tools that expect polygons to be wound in a specific direction.
Rewind GeoJSON Polygons
This feature allows you to reorient the winding order of GeoJSON polygons. The `rewind` function takes a GeoJSON object and a boolean indicating whether to reverse the winding order to follow the right-hand rule. The code sample demonstrates how to use the package to rewind a GeoJSON polygon.
const rewind = require('@mapbox/geojson-rewind');
const geojson = {
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [
[
[-101.744384765625, 39.32155002466662],
[-101.5521240234375, 39.330048552942415],
[-101.40380859375, 39.330048552942415],
[-101.33239746093749, 39.364032338047984],
[-101.041259765625, 39.36827914916011],
[-100.975341796875, 39.30454987014581],
[-101.0399169921875, 39.24501680713314],
[-101.24389648437499, 39.16414104768742],
[-101.54541015625, 39.178362282029745],
[-101.744384765625, 39.32155002466662]
]
]
}
}
]
};
const rewindedGeojson = rewind(geojson, true);
console.log(JSON.stringify(rewindedGeojson, null, 2));
The `geojson-rewind` package provides similar functionality to @mapbox/geojson-rewind by reorienting the winding order of GeoJSON polygons. It is a lightweight alternative and can be used in similar scenarios where ensuring the correct winding order is necessary.
The GeoJSON specification is picky about winding order.
This helps you generate compliant Polygon and MultiPolygon geometries. Furthermore it lets you use Canvas and other drawing libraries's default behavior to color the interior rings of Polygon and MultiPolygon features.
As NPM module:
npm install --save @mapbox/geojson-rewind
As a console utility:
# install
npm install -g @mapbox/geojson-rewind
# use
geojson-rewind foo.geojson
As a browser library: geojson-rewind.js
rewind(geojson, clockwise)
Given a GeoJSON FeatureCollection, Feature, or Geometry, return a version with inner and outer rings of different winding orders.
If clockwise
is true
, the outer ring is clockwise, otherwise
it is counterclockwise.
FAQs
enforce winding order for geojson
The npm package @mapbox/geojson-rewind receives a total of 794,101 weekly downloads. As such, @mapbox/geojson-rewind popularity was classified as popular.
We found that @mapbox/geojson-rewind demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 14 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.