topoJSON for congressional districts

Chris Wilson picture Chris Wilson · Jan 28, 2013 · Viewed 10.7k times · Source

Has anyone seen a topoJSON file for U.S. congressional districts? Alternatively, if I can locate the coordinates or a geoJSON file, is it easy to convert to arcs?

Answer

mbostock picture mbostock · Jan 28, 2013

Official cartographic boundaries are more likely to be found as shapefiles rather than GeoJSON or TopoJSON, although in this case you can find both in the jsongeo/cd113 repository on GitHub (cd113.topojson).

To get the data directly from the U.S. Census Bureau, a little Google searching will lead you to TIGER/Line shapefiles for the 113th Congress. (Congressional districts change slightly from congress to congress, so be careful that you use the appropriate version!) Clicking through to the “FTP Site Sorted by Layer” you’ll find the cryptically-named CD113 folder, and at the very bottom, tl_rd13_us_cd113.zip, a 38M zipped shapefile that contains the congressional districts for the entire United States. This file is far to large for you to use directly, but you can follow the Let’s Make a Map tutorial to use ogr2ogr and topojson to convert the shapefile to a more manageable representation.

Specifically, you’d start by converting the Shapefile to GeoJSON (101MB!):

ogr2ogr -f GeoJSON districts.json tl_rd13_us_cd113.shp

Then convert the GeoJSON to TopoJSON and simplify (only 472KB):

topojson -s 7e-9 --id-property=+GEOID -o us-congress-113.json -- districts.json

Now the first two digits of the geometry id (d.id / 1000 | 0) are the state FIPS code (see us-state-names.tsv) and the last two digits are the congressional district number (d.id % 1000) within that state. The simplification (-s) is optional, but it’s generally a good idea if you’re displaying a static map in a browser; I tuned the threshold to retain about half the points, but you could make the file even smaller by using a larger threshold.

And there you have it:

113th U.S. Congressional Districts

You’ll probably want to combine the TopoJSON file with the land and states features from us.json, since in most maps you’ll want to clip the congressional districts to the land boundary, and draw some additional boundary between states. That can be done by combining TopoJSON files using multiple input arguments to the topojson binary.