Specify radius in kilometers for d3.hexbin

I recently had a user of one of my notebooks with a hex map ask if she could specify the radius of the hexagons in kilometers instead of pixels (using d3-hexbin). I came up with a hack which looks roughly correct for the United States (using the Walmart hexbin example): How to convert from radius in km to radius in pixels? / Evan Galloway / Observable

I know this will only be approximate but does this approach make sense? Is there a better/more robust way?

Thanks!
Evan

Interesting question! There is no general answer to this problem—a regular discrete global grid on a sphere is mathematically impossible. “Spherical hexagons” are not regular either (see H3 oddities / Fil / Observable and Gray-Fuller grid oddities / Fil / Observable).

Your approach is “sort-of” correct on the contiguous states, because the projection (AlbersUSA) is not too distorted in terms of distances.

Here’s a map of the local scale, in degrees per hexagon radius:

As you can see there’s an ~7% difference between the two extremes. Is it good enough? It might be possible to find a projection with a slightly better ratio. Not sure which from the top of my head, though.

PS: note however that if any hexagon falls on Alaska, the result is going to be off by a lot—the scale on the Alaska inset of the map is about 4 times smaller than on the contiguous part.

2 Likes

Thanks @Fil! Super interesting answer, especially the map. Also thanks for the reminder about Alaska. If I end up using this, I’ll qualify it as a very rough approximation that is only useful for the contiguous U.S.

1 Like