Atlaslog
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].

Last verified 2026-11-03 · Multiple versions · Cite this page
Applies to: topojson-client 3.1 · D3 7.x · Leaflet 1.9.x
Symptom
Checklist
  1. Print Object.keys(topology) to confirm whether the top-level transform field exists.
  2. Print topology.arcs[0][0]: an integer pair like [7823, 4210] proves the coordinates are quantized.
  3. Check objects for a bbox, which can be used to reverse the translate value.
  4. Compare that bbox with the original GeoJSON bbox; a difference equal to scale times the quantized value confirms the cause.
  5. 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
All 120 field notesChinese originalRunnable examples
English edition written for Atlaslog from the original Chinese field note. Code is unchanged and runs as-is.
Cite this page

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).