Skip to content

Commit

Permalink
Update to 2017; add names.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Mar 21, 2019
1 parent a6bb794 commit 271f07f
Show file tree
Hide file tree
Showing 4 changed files with 179 additions and 5 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.sublime-*
build/
test/
img/
17 changes: 12 additions & 5 deletions prepublish
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,25 @@
rm -rvf us
mkdir -p build us

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.*
if [ ! -f build/cb_2017_us_county_5m.shp ]; then
curl -o build/cb_2017_us_county_5m.zip 'https://www2.census.gov/geo/tiger/GENZ2017/shp/cb_2017_us_county_5m.zip'
unzip -od build build/cb_2017_us_county_5m.zip cb_2017_us_county_5m.shp cb_2017_us_county_5m.dbf
chmod a-x build/cb_2017_us_county_5m.*
fi

if [ ! -f build/cb_2017_us_state_5m.shp ]; then
curl -o build/cb_2017_us_state_5m.zip 'https://www2.census.gov/geo/tiger/GENZ2017/shp/cb_2017_us_state_5m.zip'
unzip -od build build/cb_2017_us_state_5m.zip cb_2017_us_state_5m.shp cb_2017_us_state_5m.dbf
chmod a-x build/cb_2017_us_state_5m.*
fi

geo2topo -q 1e5 -n counties=<( \
shp2json -n build/cb_2015_us_county_5m.shp \
shp2json -n build/cb_2017_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 \
| node ./properties.js \
> us/10m.json
37 changes: 37 additions & 0 deletions properties.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const shapefile = require("shapefile");

Promise.all([
parseInput(),
shapefile.read("build/cb_2017_us_county_5m.shp"),
shapefile.read("build/cb_2017_us_state_5m.shp")
]).then(output);

function parseInput() {
return new Promise((resolve, reject) => {
const chunks = [];
process.stdin
.on("data", chunk => chunks.push(chunk))
.on("end", () => {
try { resolve(JSON.parse(chunks.join(""))); }
catch (error) { reject(error); }
})
.setEncoding("utf8");
});
}

function output([topology, counties, states]) {
counties = new Map(counties.features.map(d => [d.properties.GEOID, d.properties]));
states = new Map(states.features.map(d => [d.properties.GEOID, d.properties]));
for (const county of topology.objects.counties.geometries) {
county.properties = {
name: counties.get(county.id).NAME
};
}
for (const state of topology.objects.states.geometries) {
state.properties = {
name: states.get(state.id).NAME
};
}
process.stdout.write(JSON.stringify(topology));
process.stdout.write("\n");
}
129 changes: 129 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


acorn@^5.1.1:
version "5.7.3"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.7.3.tgz#67aa231bf8812974b85235a96771eb6bd07ea279"

[email protected]:
version "0.0.4"
resolved "https://registry.yarnpkg.com/array-source/-/array-source-0.0.4.tgz#a525df4a84b1376d27c677cd426a97c3882f8aca"

commander@2, commander@^2.11.0:
version "2.19.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"

d3-array@1:
version "1.2.4"
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-1.2.4.tgz#635ce4d5eea759f6f605863dbcfc30edc737f71f"

d3-dsv@^1.0.3:
version "1.1.1"
resolved "https://registry.yarnpkg.com/d3-dsv/-/d3-dsv-1.1.1.tgz#aaa830ecb76c4b5015572c647cc6441e3c7bb701"
dependencies:
commander "2"
iconv-lite "0.4"
rw "1"

d3-geo-projection@^2.0.0:
version "2.6.0"
resolved "https://registry.yarnpkg.com/d3-geo-projection/-/d3-geo-projection-2.6.0.tgz#a0acf97be5e6da251e7b0564268b58e0e6a1dc28"
dependencies:
commander "2"
d3-array "1"
d3-geo "^1.10.0"
resolve "^1.1.10"

d3-geo@^1.10.0:
version "1.11.3"
resolved "https://registry.yarnpkg.com/d3-geo/-/d3-geo-1.11.3.tgz#5bb08388f45e4b281491faa72d3abd43215dbd1c"
dependencies:
d3-array "1"

[email protected]:
version "0.6.1"
resolved "https://registry.yarnpkg.com/file-source/-/file-source-0.6.1.tgz#ae189d4993766b865a77f83adcf9b9a504cd37dc"
dependencies:
stream-source "0.3"

[email protected]:
version "0.4.24"
resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.24.tgz#2022b4b25fbddc21d2f524974a474aafe733908b"
dependencies:
safer-buffer ">= 2.1.2 < 3"

ndjson-cli@^0.3.0:
version "0.3.1"
resolved "https://registry.yarnpkg.com/ndjson-cli/-/ndjson-cli-0.3.1.tgz#aa98e1a1cc98e524ca37a7bdc03a2ae26f88e140"
dependencies:
acorn "^5.1.1"
commander "^2.11.0"
resolve "^1.3.3"

path-parse@^1.0.6:
version "1.0.6"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.6.tgz#d62dbb5679405d72c4737ec58600e9ddcf06d24c"

[email protected]:
version "0.1.3"
resolved "https://registry.yarnpkg.com/path-source/-/path-source-0.1.3.tgz#03907c595480aa2596a15a901c44f745736e7a73"
dependencies:
array-source "0.0"
file-source "0.6"

resolve@^1.1.10, resolve@^1.3.3:
version "1.10.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.10.0.tgz#3bdaaeaf45cc07f375656dfd2e54ed0810b101ba"
dependencies:
path-parse "^1.0.6"

rw@1:
version "1.3.3"
resolved "https://registry.yarnpkg.com/rw/-/rw-1.3.3.tgz#3f862dfa91ab766b14885ef4d01124bfda074fb4"

"safer-buffer@>= 2.1.2 < 3":
version "2.1.2"
resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a"

shapefile@^0.6.1:
version "0.6.6"
resolved "https://registry.yarnpkg.com/shapefile/-/shapefile-0.6.6.tgz#6fee152b9fb2b1c85f690285b692fb68c95a5f4f"
dependencies:
array-source "0.0"
commander "2"
path-source "0.1"
slice-source "0.4"
stream-source "0.3"
text-encoding "^0.6.4"

[email protected]:
version "0.4.1"
resolved "https://registry.yarnpkg.com/slice-source/-/slice-source-0.4.1.tgz#40a57ac03c6668b5da200e05378e000bf2a61d79"

[email protected]:
version "0.3.5"
resolved "https://registry.yarnpkg.com/stream-source/-/stream-source-0.3.5.tgz#b97f52d0f8ea566db071db679b985403a31e0340"

text-encoding@^0.6.4:
version "0.6.4"
resolved "https://registry.yarnpkg.com/text-encoding/-/text-encoding-0.6.4.tgz#e399a982257a276dae428bb92845cb71bdc26d19"

topojson-client@3, topojson-client@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/topojson-client/-/topojson-client-3.0.0.tgz#1f99293a77ef42a448d032a81aa982b73f360d2f"
dependencies:
commander "2"

topojson-server@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/topojson-server/-/topojson-server-3.0.0.tgz#378e78e87c3972a7b5be2c5d604369b6bae69c5e"
dependencies:
commander "2"

topojson-simplify@^3.0.0:
version "3.0.2"
resolved "https://registry.yarnpkg.com/topojson-simplify/-/topojson-simplify-3.0.2.tgz#8a2403e639531500fafa0c6594e8b0fadebc2c02"
dependencies:
commander "2"
topojson-client "3"

0 comments on commit 271f07f

Please sign in to comment.