Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 13.1 — Geographic Data: GeoJSON and TopoJSON
Data Visualization · Example 1 of 2

Read TopoJSON, turn it into GeoJSON and check the common mistakes

Station S01 (Quay) is one of the CSV's rows. Ardenvale is a made-up island, so no real map shows it.

A map is data first: a list of places, each with shapes made of [longitude, latitude] points. GeoJSON writes every shape out in full, TopoJSON stores each shared border once, and a ring written in the wrong direction can make a small island fill the whole world.

Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.

Ready for more? This phase has 4 hands-on exercises with automatic checks.

Practice questions

Write the code in the editor, run it, then open the model answer to compare.

01

Write loadGeo(name) that fetches a TopoJSON file, throws a clear error on a bad status, and returns the first object's features. Test it with the correct and a wrong name.

02

Write checkStations(stations, districts) that returns the list of station ids not inside the district their CSV row names. Run it on the real stations; then swap one station's coordinates to see it found.

Explain it without notes

01

What is the order of a coordinate in GeoJSON, and what goes wrong if you reverse it?

02

What does TopoJSON store that GeoJSON does not, and why is the file smaller?

03

Why does a polygon with the wrong winding fill the whole map in D3?

04

How would you detect a wrongly wound polygon in code?

Read TopoJSON, turn it into GeoJSON and check the common mistakes

Preview

Press Run to see the page.

Console

Nothing logged yet.

Expected console output

type: Topology | objects: districts, coast, river
shared arcs: 33 | bbox: -30.64517, 39.36961, -30.55277, 39.43066
FeatureCollection with 6 features: harbour, old-town, university, riverside, hillcrest, westpark
harbour Polygon first point [lon, lat]: -30.6024, 39.3703
Ardenvale: 2684 characters as TopoJSON, 6623 as GeoJSON
World 1:110m: 107760 characters as TopoJSON, 436088 as GeoJSON, 177 countries
[lon, lat] = -30.59415, 39.39147 -> Harbour
[lat, lon] = 39.39147, -30.59415 -> nowhere
Could not load ardenvale.json (the server answered 404).