block by mbostock 5562380

California Population Density

Full Screen

Source: American Community Survey, 2014 5-Year Estimate

This map was inspired by a similar map found on Wikipedia. I wasn’t wild about the diverging color scale, so I thought it would be a fun challenge to recreate. Amazingly, a single command is used to join the Census Bureau’s shapefile and CSV, and then to project, convert to TopoJSON, and simplify:

geo2topo -n \
  tracts=<(ndjson-join 'd.id' \
    <(shp2json cb_2014_06_tract_500k.shp \
      | geoproject 'd3.geoAlbers().parallels([34, 40.5]).rotate([120, 0]).fitExtent([[10, 10], [950, 1090]], d)' \
      | ndjson-split 'd.features' \
      | ndjson-map 'd.id = d.properties.GEOID.slice(2), d') \
    <(ndjson-cat cb_2014_06_tract_B01003.json \
      | ndjson-split 'd.slice(1)' \
      | ndjson-map '{id: d[2] + d[3], B01003: +d[0]}') \
    | ndjson-map 'd[0].properties = {density: Math.floor(d[1].B01003 / d[0].properties.ALAND * 2589975.2356)}, d[0]') \
  | toposimplify -p 1 -f \
  | topomerge -k 'd.id.slice(0, 3)' counties=tracts \
  | topomerge --mesh -f 'a !== b' counties=counties \
  | topoquantize 1e5 \
  > topo.json

The Census Bureau is great, though the user interface of the American FactFinder is somewhat onerous. Here are the nineteen steps to download the data:

  1. Go to factfinder2.census.gov.
  2. Find where it says “American Community Survey” and click “get data »”.
  3. Click the blue “Geographies” button on the left.
  4. In the pop-up, select census tract in the “geographic type” menu.
  5. Select California in the resulting “state” menu.
  6. Click “All Census Tracts within California”.
  7. Click the “ADD TO YOUR SELECTIONS” button.
  8. Click “CLOSE” to dismiss the pop-up.
  9. Click the blue “Topics” button on the left.
  10. In the pop-up, expand the “People” submenu.
  11. Expand the “Basic Count/Estimate” submenu.
  12. Click “Population Total”.
  13. Click “CLOSE” to dismiss the pop-up.
  14. In the table, click on the most recent ACS 5-year estimate named “TOTAL POPULATION”.
  15. On the next page, click the “Download” link under “Actions”.
  16. In the pop-up, click “OK”.
  17. Wait for it to “build” your file.
  18. When it’s ready, click “DOWNLOAD”.
  19. Finally, expand the downloaded zip file (ACS_14_5YR_B01003.zip).

Personally, I prefer the Census Bureau’s developer API to retrieve data. It uses simple, readable URLs where you can substitute a year (2014), a FIPS code (06 for California), a census variable name (B01003_001E for total population), and other parameters to download the desired data from the command line without fighting a convoluted user interface. Census Reporter also provides a convenient interface to the data, albeit with some limitations such as dataset size.

The above map shows individual census tracts. For faster download and rendering, and to reduce antialiasing artifacts, you can merge tracts of the same color (population density interval) using topomerge. This is so effective at compressing the data that you can reasonably use block groups instead of tracts for greater resolution. For static maps, consider using geo2svg for even faster rendering.

For more examples of the d3-geo and TopoJSON command-line interface, see us-atlas.

index.html

package.json

prepublish