Unlisted
Edited
Dec 3, 2022
1 fork
Importers
5 stars
Insert cell
Insert cell
Insert cell
// Old style function, deprecated, leaving it here for importers.
// I'm adding a warning that it will be removed by Jan 2024.
function normalizeWindingInPlace(p) {
console.warn(
"The normalizeWindingInPlace is deprecated and will be removed by Jan 2024. See https://observablehq.com/@fil/normalize-winding"
);
const g = p.geometry || p;
if (p.type === "FeatureCollection") {
p.features = p.features.map(normalizeWindingInPlace);
} else if (p.type === "GeometryCollection") {
p.geometries = p.geometries.map(normalizeWindingInPlace);
} else if (g.type === "MultiPolygon") {
g.coordinates = g.coordinates.map((poly) =>
poly.map((ring, i) =>
(i > 0) ^
(d3.geoArea({ type: "Polygon", coordinates: [ring] }) > 2 * Math.PI)
? ring.reverse()
: ring
)
);
} else if (g.type === "Polygon") {
g.coordinates = g.coordinates.map((ring, i) =>
(i > 0) ^
(d3.geoArea({ type: "Polygon", coordinates: [ring] }) > 2 * Math.PI)
? ring.reverse()
: ring
);
}
return p;
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more