Public
Edited
Sep 21, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getInnerBins = (feature) => {
/*
For each feature:
- chop off last point since it dupes the first
- calculate center (points[0] + points[3] / 2) or turf.center

use turf.midpoint? or no? maybe turf.rewind for winding help

For each point:
- grab next point (i == length ? 0 : i + 1)
- calculate midpoint distance
- grab prev point (i == 0 ? length - 1)
- calculate midpoint dist
*/
const points = feature.geometry.coordinates[0].slice(0, -1);
const centerPoint = [
(points[0][0] + points[3][0]) / 2,
(points[0][1] + points[3][1]) / 2
];
const polygons = [];
points.forEach((point, i) => {
const nextPoint = points[i === points.length - 1 ? 0 : i + 1];
const prevPoint = points[i === 0 ? points.length - 1 : i - 1];
const nextMidPoint = [
(point[0] + nextPoint[0]) / 2,
(point[1] + nextPoint[1]) / 2
];
const prevMidPoint = [
(point[0] + prevPoint[0]) / 2,
(point[1] + prevPoint[1]) / 2
];
polygons.push(
turf.rewind(
turf.polygon([
[centerPoint, nextMidPoint, point, prevMidPoint, centerPoint]
])
)
);
});
return polygons;
}
Insert cell
Insert cell
bins = {
const bbox = [-125, 25, -65, 50];
const cellSide = 30;
const options = { units: "miles", mask: usa };
const hexes = turf.hexGrid(bbox, cellSide, options);
return {
...hexes,
features: _.flatMap(hexes.features.map((f) => getInnerBins(f)))
};
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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