Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make a chloropleth based on zip codes?

Tags:

d3.js

topojson

I want to use d3 to create a chloropleth that assigns different colors to different zip code regions in the United States. Similar to this, except with zip codes: http://bl.ocks.org/mbostock/4060606

However, I can't find a topojson of US zip codes. This offers a way to generate the topojson for zip codess:https://github.com/mbostock/us-atlas

but my Mac has been running their script for hours on end. Oddly, I can't find anyone on the Internet who has successfully generated the file of zip codes.

I could also use zip3 regions - basically zip code regions characterized by the first 3 digits. However, I can't find any topojson for this division.

Where can I find topojsons or files containing the shapes of either US zip codes or zip3 regions?

like image 556
dangerChihuahua007 Avatar asked Mar 30 '14 09:03

dangerChihuahua007


1 Answers

A zip code topojson is going to be too large to work with. A Zip3 geoJSON file is over 550MB with no simplification. With a simplification of 0.00001 it's over 370MB. If I take it to a simplification of 0.001 then you can get 39MB.Which will get down to 1.1MB after running it through topojson but you end up with a USA map that looks like a polygon from Everquest Texas is massively deformed. I think the happy medium is is 0.0001 this gives you a topojson file of bout 4.8MB. Here is the process.

  1. Download your Zip3 file here
  2. Extract to your working directory
  3. Run ogr2ogr -simplify 0.0001 -f GeoJSON zip3.json zip3.shp
  4. Run topojson --id-property ZIP3 -o zip3topo.json -- zip3.json

The ogr2ogr will take some time but now you have a topojson file that will render to look like this. enter image description here

like image 73
Ian H Avatar answered Dec 23 '22 01:12

Ian H