Skip to content

Instantly share code, notes, and snippets.

@mbostock
Last active November 13, 2016 21:45
Show Gist options
  • Star 16 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbostock/a66f500bbaa661bab1c27b62f5c38953 to your computer and use it in GitHub Desktop.
Save mbostock/a66f500bbaa661bab1c27b62f5c38953 to your computer and use it in GitHub Desktop.
U.S. Atlas, Redux [UNLISTED]
license: bsd-3-clause
#!/bin/bash
# Make a working directory.
mkdir -p counties
# Download the U.S. county boundaries, one-million scale.
# https://nationalmap.gov/small_scale/atlasftp.html
curl -o counties/counties.tar.gz 'https://prd-tnm.s3.amazonaws.com/StagedProducts/Small-scale/data/Boundaries/countyp010g.shp_nt00934.tar.gz'
# Expand the downloaded tarball into the working directory.
tar -vxzm -C counties -f counties/counties.tar.gz
# Convert to TopoJSON!
# shp2json converts the counties shapefile to GeoJSON.
# ndjson-filter removes “water” counties (e.g., Great Lakes).
# ndjson-map assigns an id and removes extraneous properties.
# geostitch removes antimeridian cuts, if any.
# geoproject applies D3’s U.S. Albers composite equal-area projection.
# geo2topo converts the GeoJSON to quantized TopoJSON.
# toposimplify simplifies the TopoJSON while preserving topology.
# topomerge merges counties into states, and then states into the nation.
geo2topo -n -q 1e5 counties=<( \
shp2json -n counties/countyp010g.shp \
| ndjson-filter '!/000$/.test(d.properties.ADMIN_FIPS)' \
| ndjson-map '(d.id = d.properties.ADMIN_FIPS, delete d.properties, d)' \
| geostitch -n \
| geoproject -n 'd3.geoAlbersUsa()') \
| toposimplify -f -p 0.25 \
| topomerge states=counties -k 'd.id.slice(0, 2)' \
| topomerge nation=states \
> us-albers-10m.json
# Convert to SVG!
cat us-albers-10m.json \
| topo2geo -n counties=- \
| geo2svg -n -p 2 \
> us-albers-10m.svg
@mbostock
Copy link
Author

mbostock commented Nov 2, 2016

us-albers-10m

@curran
Copy link

curran commented Nov 2, 2016

Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment