Skip to content

Instantly share code, notes, and snippets.

@wboykinm
Last active March 21, 2018 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wboykinm/c9a091b72e8cf24b46881c8154837221 to your computer and use it in GitHub Desktop.
Save wboykinm/c9a091b72e8cf24b46881c8154837221 to your computer and use it in GitHub Desktop.
A variation on Mike Bostock's us-atlas (https://github.com/topojson/us-atlas) that includes quantized metro areas as a separate object
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/bin/bash
# mad requirements:
npm install topojson-client topojson-server topojson-simplify shapefile ndjson-cli d3-geo-projection mapshaper -g
rm -rvf us
mkdir -p build us
# get both metros and counties
if [ ! -f build/cb_2015_us_cbsa_5m.shp ]; then
curl -o build/cb_2015_us_cbsa_5m.zip 'https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_cbsa_5m.zip'
unzip -od build build/cb_2015_us_cbsa_5m.zip cb_2015_us_cbsa_5m.shp cb_2015_us_cbsa_5m.dbf
chmod a-x build/cb_2015_us_cbsa_5m.*
fi
if [ ! -f build/cb_2015_us_county_5m.shp ]; then
curl -o build/cb_2015_us_county_5m.zip 'https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_county_5m.zip'
unzip -od build build/cb_2015_us_county_5m.zip cb_2015_us_county_5m.shp cb_2015_us_county_5m.dbf
chmod a-x build/cb_2015_us_county_5m.*
fi
# awkwardly build them all
geo2topo -q 1e5 -n counties=<( \
shp2json -n build/cb_2015_us_county_5m.shp \
| ndjson-filter '!/000$/.test(d.properties.GEOID)' \
| ndjson-map '(d.id = d.properties.GEOID, delete d.properties, d)' \
| geoproject -n 'd3.geoAlbersUsa().scale(1280).translate([480, 300])') \
| toposimplify -f -p 0.25 \
| topomerge states=counties -k 'd.id.slice(0, 2)' \
| topomerge nation=states \
> us/10m.json
geo2topo -q 1e5 -n metros=<( \
shp2json -n build/cb_2015_us_cbsa_5m.shp \
| ndjson-filter '!/000$/.test(d.properties.GEOID)' \
| ndjson-map '(d.id = d.properties.GEOID, delete d.properties, d)' \
| geoproject -n 'd3.geoAlbersUsa().scale(1280).translate([480, 300])') \
| toposimplify -f -p 0.25 \
> us/10m-metros.json
mapshaper -i combine-files us/10m.json us/10m-metros.json -o us/10m-all.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment