Atlaslog / Field Notes / Loading & display
Field note · Loading & display
TopoJSON loses transform and coordinates become integers like 7823
Quick answer
TopoJSON quantizes coordinates to integers and stores the restore parameters in a top-level transform block. When a processing script strips that block, topojson.feature returns raw quantized integers and the layer renders empty or collapses near [0,0].
Symptom
- topojson.feature(topology, topology.objects.districts) yields coordinates such as [7823, 4210] instead of [116.397, 39.909].
- Object.keys(topology) returns ['type', 'arcs', 'objects'] with no transform key.
- The layer is blank, or every feature piles up around [0,0].
Checklist
- Print Object.keys(topology) to confirm whether the top-level transform field exists.
- Print topology.arcs[0][0]: an integer pair like [7823, 4210] proves the coordinates are quantized.
- Check objects for a bbox, which can be used to reverse the translate value.
- Compare that bbox with the original GeoJSON bbox; a difference equal to scale times the quantized value confirms the cause.
- Re-export from the source with topojson -q 1e4 -s 1e-3 so the transform block is written again.
Fix
Re-export with npx topojson -q 1e4 -s 1e-3 -o districts.topo.json districts.geojson so the transform block survives. As a client-side stopgap, spread the topology and add transform scale [(135-73)/1e5, (54-3)/1e5] and translate [73, 3] before calling topojson.feature.
Code
{
"type": "Topology",
"transform": { "scale": [0.001, 0.001], "translate": [73, 3] },
"arcs": [...],
"objects": { ... }
}console.log(Object.keys(topology));
console.log(topology.arcs[0][0]);
const g = topojson.feature(topology, topology.objects.districts);
console.log(g.features[0].geometry.coordinates[0][0]);
// [7823, 4210] <- 未还原
Watch out
- Trimming the file down to only objects and arcs for size, which silently destroys the coordinate system.
- Hand-guessing scale and translate and shipping it: residuals must stay under scale/2, i.e. 0.00062 degrees or about 69 metres, otherwise the layer is visibly displaced.
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Atlaslog (2026). TopoJSON loses transform and coordinates become integers like 7823. https://www.jingweizhi.com/en/cookbook/topojson-missing-transform.html (accessed 2026-11-03).