A demonstration of the new command-line tools in TopoJSON 2.0, d3-geo-projection 1.1 and ndjson-cli.
Last active
November 13, 2016 21:45
-
-
Save mbostock/a66f500bbaa661bab1c27b62f5c38953 to your computer and use it in GitHub Desktop.
U.S. Atlas, Redux [UNLISTED]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: bsd-3-clause |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment