indiaciv, part 1: India on hexes
A while ago Andrej Karpathy put up usaciv, the United States drawn as a turn-based strategy map. Hexes, terrain, rivers and cities, but every tile comes from real data. I lost an evening to it and then spent the next one wondering what India would look like.
So I built it: indiaciv. It is a hex map of India where terrain, rivers, borders, 1.46 billion people, 983 cities and five “yields” (food, production, gold, science and culture) are all computed from public datasets. You can switch lenses, hover any hex to see where its numbers come from, and flip between four visual themes.

This is a series about how it works, from projections to pixels. It goes deep on the calculations, because that’s where the interesting decisions were.
- India on hexes (this post): the architecture, the projection, the grid and what counts as India
- Terrain from satellites: elevation, land cover, terrain rules, rivers on hex edges
- Putting 1.46 billion people on the map: population, the state-total invariant, cities
- Economics as game yields: food, production, gold, science and culture from real statistics
- Climate, resources and roads: IMD normals, a lapse-rate bug, OSM infrastructure
- Drawing 50,000 sprites in a browser: procedural art, culling, themes and deployment
A note on how this was made: I built indiaciv with Claude Code as a pair programmer, from the first
make fetchto the last pixel theme. I set the rules (the data sources, the boundary rule, what to leave out) and checked every result against the map and the source tables. Claude wrote most of the code and drafted these posts with me.
The shape of the thing
There is no backend. The project is two halves joined by one contract:
- Offline, a Python pipeline (managed with
uv, driven bymake) downloads about twenty public datasets, puts all of them on the same hex grid, derives game state (terrain, cities, yields), and writes the result as flat binary arrays. - Online, a static page (Vite and PixiJS) fetches those arrays and draws the map. Everything, textures included, is painted in code when the page loads. There isn’t a single image file in the map.
The contract is site/data/: a manifest.json describing every layer, plus about 25 files like
terrain.u8, state.u8 and lens-food.u8. Each is one byte (or two, for districts) per hex, in the
same order. The whole bundle is 1.6 MB, or 325 KB brotli-compressed. The browser never sees a
shapefile or a GeoTIFF.
Two rules hold the pipeline together:
- Every source is recorded. Each fetcher writes the URL, sha256, fetch date and licence to
data/manifest.yaml. The map’s details panel and About page show, for any hex, exactly which sources produced its numbers. make validatemust pass. It runs 61 checks: state population and economy totals must match their sources within 2%, the Thar has to be desert, the Ganga has to pass Varanasi, and so on. Most of the bugs I’ll describe in this series were caught by one of these checks.
Why hexes, and which hexes
Squares are easy, but a square has two kinds of neighbour: four across an edge and four across a corner, at different distances. Hexes have six neighbours, all across an edge and all the same distance away. That’s why strategy games use them, and it matters for the data too. “Everything within three steps of a city” is a clean, round-ish region on a hex grid.
I went with flat-top hexes, 20 km across the flats. At that size India comes out at about 9,200 hexes. That’s enough to show the Western Ghats as a ridge and the Gangetic plain as a plain, and small enough to draw at 60 fps on a laptop.
The numbers fall out of the geometry. If the distance across the flats is 20 km, the circumradius (centre to corner) and the area are
Corner sits at angle from the centre, and edge joins corner and corner , so edges are numbered 0 NE, 1 N, 2 NW, 3 SW, 4 S, 5 SE. That numbering looks like a detail, but it’s baked into two binary files. Rivers are stored as a 6-bit mask per hex (bit set means a river runs along edge ), and the Python pipeline and the JavaScript renderer must agree on it. Part 2 covers rivers.
Offset coordinates
Each hex has an address (col, row). Columns step 1.5 R to the east. Rows step to the
south, and every odd column is pushed half a row down (the “odd-q” layout). The centre of hex
is
in projected metres. Rows increase southward so the grid reads like an image: row 0 is the top, and every layer is stored row-major. The value for hex lives at index in every array. Going the other way, from a mouse position to a hex, converts to cube coordinates and rounds, the standard trick from Red Blob Games.
Here is the real grid: 173 columns × 171 rows, coloured by state. Hover (or tap) a hex to see its address, its index in the byte arrays, the value stored there, and its six neighbours.
One trap with odd-q: a hex’s neighbours depend on whether its column is odd or even. The north-east
neighbour of (66, 41) is (67, 40), but the north-east neighbour of (67, 41) is (68, 41). I
wrote the neighbour table once in Python and once in JavaScript, and the two copies are kept
identical on purpose.
Flattening the Earth: picking a projection
A hex grid needs a flat plane, and India sits on a curved Earth. The obvious shortcut is to lay the grid out in latitude and longitude directly. That doesn’t work, because a degree of longitude gets shorter as you go north:
A cell 0.18° wide is 19.8 km across at Kanyakumari (8°N) but only 16.4 km at Leh (34°N). That’s 17% narrower, so hexes in Ladakh would cover far less ground than hexes in Kerala, and every per-hex total would be skewed.
Instead, the grid lives in EPSG:7755, “WGS 84 / India NSF LCC”. It’s the Lambert conformal conic projection that India’s National Spatial Framework defines for the whole country, with standard parallels at 12°28′N and 35°10′N. Between those two parallels the scale error stays small, and across all of India a 20 km hex on the map is between 19.5 and 20.4 km on the ground (about ±3%). Being conformal, it also keeps shapes locally right, so hexes stay hexagonal on the ground.
Every source gets reprojected into EPSG:7755 before anything is measured. The grid itself is just an origin, a size and :
{ "x0": 2767281.1, "y0": 5503428.1, "cols": 173, "rows": 171,
"R": 11547.005, "crs": "EPSG:7755", "layout": "flat-top odd-q, rows increase southward" }
The origin is the north-west corner of India’s bounding box, pushed out by three hexes of margin so the neighbouring countries and sea get drawn at the edges.
What counts as India?
This turned out to be the first real decision, not a technicality.
The outline. Global datasets disagree about India’s borders, most visibly in Kashmir and Aksai Chin, and the commonly used ones don’t follow India’s official boundary. So one rule is absolute: India’s shape comes only from the Survey of India outline (via DataMeet), never from a global dataset. Natural Earth is used for exactly one thing, telling neighbouring land apart from sea outside India. Districts are DataMeet’s Census 2011 polygons, mapped to today’s states and union territories using LGD codes, so Telangana and Ladakh come out right.
The coverage rule. A 20 km hex on a coastline is partly land and partly sea, or partly India and partly Pakistan. I rasterise the outline at 1 km and use exactextract to measure what fraction of each hex falls inside it, weighting every pixel by the exact share of it the hex covers. Then:

About 1,200 hexes are partial, and the 50% line decides each one. It’s a fair rule: across a long coastline, the land you lose on one hex roughly balances the sea you gain on the next.
Two exceptions. First, small islands. Lakshadweep’s atolls are a few square kilometres each, so no hex is ever half inside them, and they would simply vanish. Any island smaller than half a hex that isn’t next to an existing Indian hex keeps the hex it sits in. The “isn’t next to” part matters: without it, every islet of the Sundarbans would add a hex and the delta would bloat into the bay. This rule saves 51 hexes, including the two nearly empty outlined hexes in the Gulf of Kutch above.
Second, every state and union territory gets at least one hex. Chandigarh is 114 km², a third of a hex, so it would otherwise disappear. It gets the hex at the representative point of its largest district.
The result is 9,230 Indian hexes, about 3.2 million km². Every one has a state (state.u8, a
1-based index into admin.json) and a district (district.u16). Those two arrays are the backbone
for everything in the next three parts.
See the Gulf of Kutch on the live map →
Next: terrain
So far we have 9,230 empty hexes with addresses. In part 2 they get ground under them: averaging the Copernicus elevation model and ESA’s land-cover map over each hex, a rule table that decides whether a hex is hills, jungle or desert, and why rivers run along the edges of hexes rather than through them.