Published
Edited
Aug 10, 2022
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
lookupMap = bartStations.features.reduce((map, feature) => {
// Make a map like {[hexagon]: [id, id, ...]}
const [lon, lat] = feature.geometry.coordinates;
const h3Index = h3.geoToH3(lat, lon, res);
if (!map[h3Index]) map[h3Index] = [];
map[h3Index].push(feature);
return map;
}, {})
Insert cell
Insert cell
function kRingResults(searchLocation) {
const lookupIndexes = kRingIndexes(searchLocation);
// Find all points of interest in the k-ring
return lookupIndexes.reduce((output, h3Index) => [...output, ...(lookupMap[h3Index] || [])], []);
}
Insert cell
function kRingIndexes(searchLocation, pad = 0) {
const origin = h3.geoToH3(searchLocation.lat, searchLocation.lng, res);
// Transform the radius from km to grid distance
const radius = 1 + Math.round(searchRadiusKm / h3.edgeLength(res, h3.UNITS.km)) + pad;
return h3.kRing(origin, radius);
}
Insert cell
Insert cell
function haversineResults(searchLocation) {
return bartStations.features.filter(
feature => haversineDistance(
[searchLocation.lng, searchLocation.lat],
feature.geometry.coordinates,
{units: 'kilometers'}
) < searchRadiusKm
);
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more