Switch branches/tags
Nothing to show
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



This exploration was undertaken to kick the tires of tools for generating TopoJSON. The specific data used as input for the testing was a "shapefile" for the Seattle City Council Districts. (A project needed that info in TopoJSON; this report documents how I went about converting the file.)


TopoJSON is from the mind of Mike Bostock. As part of that effort he created a small, sharp tool for generating TopoJSON files. The tool is appropriately called topojson.

Since the TopoJSON format is well-spec others have gone on to implement TopoJSON generators as well. Bostock mentions one example, Sean Gillies' topojson.py.

In the process of my exploration of the TopoJSON tools, I have direct experience with Bostock's util but I have not tested Gillies' topojson.py.

Two tools were used during this exploration:

  1. topojson: it can be installed via npm install topojson
  2. GDAL: on OSX, it can be installed via brew install gdal

This directory

Contained in the directory wherein this README.md is to be found are three other files: one input and two separate outputs (one good, one bad) which are the results of attempting to convert a shapefile to TopoJSON.

The bad output is the result of my naive first attempt to do the conversion in one step. The good output is what eventually I figured out how to produce in two steps.

The input file

Seattle_City_Council_Districts.zip which was downloaded from: https://data.seattle.gov/City-Business/City-Council-Districts/th8u-8xnq

The output file

The two output files are named with the pattern foo.good.json and foo.bad.json, where foo=seattle-city-council-districts-as-topojson.

The bad output file


This file was generated by mbostocks's topojson util:

topojson --out seattle-city-council-districts-as-topojson.bad.json City_Council_Districts.shp

topojson can read from multiple file formats, including shapefiles (*.shp), but there were problems with it convert the Seattle City Council District file. Click on the above linked filename to see the file rendered on GitHub. Notice the orange line at the north pole. That is the TopoJSON rendered.

Read the actual JSON file and note the nutty bbox and transform:

bbox: [
translate: [

On the other hand, if this file is uploaded to http://www.mapshaper.org/ then it renders well. Note though that there is no "context" for the rendering i.e no global map and the Seattle City Districts are scaled to take up the full window's allocated pixels. Perhaps mapshaper is not using the bbox and such, which enables it to render?

I explored topojson's command line switches but was not getting anywhere, so I switch to Plan N+1 which eventually got me better results.

The good output file


This file was generated in two stages: first by using GDAL's ogr2ogr to translate the shapefile to GeoJSON, and then the GeoJSON was fed to topojson

ogr2ogr -f GeoJSON -t_srs crs:84 seattle-city-council-districts-as-geojson.json City_Council_Districts.shp
topojson --out seattle-city-council-districts-as-topojson.good.json seattle-city-council-districts-as-geojson.json

Click on the above linked filename to see it rendered on GitHub. Notice how the districts are colored orange, similar to the TopoJSON in the bad file.

I guess ogr2ogr is better at handling shapefiles. TopoJSON was invented in order to make a more efficient geo-info JSON format that the rather naive GeoJSON, so it stands to reason that Bostock's tool is better at GeoJSON-->TopoJSON than it is at Shapefile-->TopopJSON. Or at least that was my hunch and now we have the TopoJSON files for Seattle's City Districts. (I have no ability to judge the quality of the input Shapefile; maybe the thing was funky.)

This exploration report is just a write-up that might help someone in the future dealing with the same hassles.