Digital Garden

The Shanghai Digital Twin: Resurrecting 152,902 Buildings

2026-10-12 · ~5 min read · Shanghai · digital twin · Blender · OpenStreetMap · k-NN

When a civilization begins writing the biography of a city, it does not need ink first — it needs a coordinate system. On this day, Shanghai’s biography opens on the F: drive: a digital-twin dynasty built on OpenStreetMap data as its foundation and Blender as its temple lays its first brick.

I. The data expedition: from 26 MB to 152,902 buildings

Everything began with Geofabrik’s daily snapshot. The October 11, 2026 data — 26 MB — holds all of Shanghai: 15.3 million building footprints, 6.2 million primary roads, and 26 metro lines carrying their official colors. The artisans of conversion first stripped the city’s skeleton with osmium, then hit the first gate: the maglev’s trace covers Line 1’s color. This is not an error but a geographic deception — two lines share the same corridor in the data. The repair script ran overnight, and all twenty metro lines and the official palette fell back into place.

The real challenge was height. Of Shanghai’s building army, only about one in a thousand carries a height tag — Shanghai Tower at 632 m, the World Financial Center at 492 m, the Oriental Pearl Tower at 468 m, and the Jin Mao Tower at 420.5 m, a handful of riders standing before the whole host. The remaining 14.4 million towers without heights are like an army with no roster.

II. The coronation of k-NN: calculating a building’s fate from its neighbors

The solution carries a statistician’s elegance: for every height-less building, search a 900 m radius for neighbors with height tags, weight by road class and building type, and infer its stature with a k-nearest-neighbors spatial model. This is not divination but the mathematics of geopolitics — towers cluster, slums self-segregate, and the vertical distribution of a city is never random noise.

The five-fold cross-validation was the coronation: a 2.9 m median error, with 64% of predictions landing within ±30% of truth. As a control, the team also downloaded the global human-settlement height raster (a 72 MB GeoTIFF) — its correlation with actual OSM heights was only 0.14, rejected on the spot. In the world of data, correlation is the only crown.

Satellite calibration was the final gate. Chinese satellite imagery often carries the GCJ-02 “mirror offset,” so the team ran a ±750 m offset search anchored on Shanghai — the offset between the ESRI and Google imagery and OSM geometry was zero meters, so buildings sit strictly on the correct roads in the imagery. Ninety-nine landmark buildings were parsed, thirty-plus mismatched matches removed, and coordinates were cross-examined by three sources: OSM footprints, Nominatim, and the official Tianditu coordinates.

III. The delivered dynasty: ten collections and five cameras

In the final .blend file, Shanghai is partitioned into ten collections: GROUND, BUILDINGS, LANDMARKS, WATER, ROADS, METRO, BOUNDARIES, LABELS, CAMERAS, LIGHTS. Thirty-two point five six million vertices, 2.84 million faces, 62,143 primary roads, 5,440 water polygons (the Huangpu River’s Lujiazui stretch exact), and four hand-modeled landmarks. Five preset cameras are already mounted: the Bund overlook, the Lujiazui aerial, the whole-city bird’s-eye, the Wheelock view, and the Oriental Pearl close-up — open the file, and the city is waiting for its audience.

The data is yesterday’s fresh corpse (October 11); the model is today’s immortality. The README honestly records the boundaries: heights of untagged buildings are estimates, buildings are extruded prisms, the landmarks’ rooftop details are absent, and satellite imagery of different districts may differ in capture time. The first lesson of a digital twin has always been this: record the boundaries honestly first, then talk about immortality.

Real coordinates

Comments

← Digital Garden