Public
Edited
Nov 7, 2023
1 fork
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
hexagons = {
let cells = new Set(japanHexagons);
function includedNeighbors(origin) {
const neighbors = h3.kRing(origin, kRingSize)
return neighbors.reduce(
(count, n) => count += cells.has(n) ? 1 : 0, 0
);
}
function dilate() {
for (const cell of cells) {
const neighbors = h3.kRing(cell, 1);
for (const neighbor of neighbors.filter(n => !cells.has(n))) {
if (includedNeighbors(neighbor) >= dThreshold) {
cells.add(neighbor);
}
}
}
}
function erode() {
for (const cell of cells) {
if (includedNeighbors(cell) <= eThreshold) {
cells.delete(cell);
}
}
}
for (let i = 0; i < passes; i++) {
if (firstOp === 'dilate, then erode') {
dilate();
erode();
} else {
erode();
dilate();
}
}
return Array.from(cells);
}
Insert cell
japanHexagons = {
let cells = [];
function addPolygon(polygon) {
cells = cells.concat(h3.polyfill(polygon, h3Resolution, true));
}
japan.features.forEach(feature => {
if (feature.geometry.type === 'MultiPolygon') {
feature.geometry.coordinates.map(addPolygon);
} else if (feature.geometry.type === 'Polygon') {
addPolygon(feature.geometry.coordinates);
}
});
return cells;
}
Insert cell
Insert cell
Insert cell
Insert cell
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