Platform
Solutions
Resources
Pricing
Sign in
Sign up
Zachary Marois
Workspace
Fork
Published
By
Zachary Marois
Edited
Aug 10, 2022
Fork of
H3 Radius Lookup
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.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mapView
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
res
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
searchRadiusKm
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lookupMap
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
kRingResults
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
kRingIndexes
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
haversineResults
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bartStations
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
h3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3Fetch
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
geojson2h3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
mapboxgl
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
makeCircle
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
haversineDistance
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML