liveBook · Manning

TopoJSON

As explained in D3.js in Action, Third Edition

TopoJSON is an extension of GeoJSON that encodes shared geographic topology and geometries in a compact form.

TopoJSON extends GeoJSON for geographic data by storing shared line segments as reusable arcs instead of repeating each feature’s coordinates. This removes redundant borders, produces smaller web-ready files, and supports detailed maps. Unlike GeoJSON, TopoJSON is not directly readable by D3; decode it with topojson-client before drawing. section 13.1.2 section 13.7

Use TopoJSON in a D3 mapping workflow:

  • Install and import topojson-client with npm. section 13.5
  • Convert a topology object into GeoJSON features with topojson.feature(topology, topology.objects.<name>). section 13.5
  • Extract shared borders separately with topojson.mesh() when they should be rendered as one geometry. section 13.5
  • Render the converted features through a D3 projection and geo path generator, then append the resulting paths to SVG. section 13.5

Mapping France’s departments

A France map converts france.objects.FRA_adm2 into department features, extracts its borders with mesh(), and draws both through a Mercator projection. Rendering the borders as one additional path avoids overlap and creates a cleaner map. The result displays France’s 96 departments and can be combined with city locations for a Nobel laureate birthplace visualization. section 13.5

Figure 13.3 While shared borders appear twice in GeoJSON, TopoJSON reduces redundancy by merging them into a single arc.
figure

Compare duplicated GeoJSON borders with TopoJSON’s single shared arc. section 13.1.2

How D3.js in Action, Third Edition covers it

How deep it goes
Explains arcs, redundancy, decoding, feature extraction, mesh extraction, and SVG rendering, but not TopoJSON file construction.
Examples
Uses shared country borders, France’s 96 departments, Mercator maps, and Nobel laureate birthplace locations.
What it assumes
Assumes basic D3 and SVG mapping concepts while introducing TopoJSON decoding and shared-border handling.
What you can do after
Apply it via topojson-client to decode topology, extract features and borders, and render compact geographic maps with D3.
How it connects
Connects TopoJSON with GeoJSON, D3, topojson-client, geographic projections, geo paths, and SVG.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.