Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
US Zip Codes

This is a d3.js visualization of US zip codes.

Original zip code dataset from Geocommons.

5MB shapefile with properties such as zipcode, state, name, population, area, more.

http://geocommons.com/overlays/54893 (Thank you Bill Greer)

This converts it nicely:

topojson \
  -p name=PO_NAME \
  -p zip=ZIP \
  -p state=STATE \
  -o zips_us_topo.json \
  zip_codes_for_the_usa.shp
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.zip {
fill: none;
stroke: #CCC;
stroke-width: .5px;
}
</style>
<body>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/queue.v1.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script>
var width = 960,
height = 500;
var path = d3.geo.path();
var svg = d3.select("body").append("svg")
.attr("width", width)
.attr("height", height);
queue()
.defer(d3.json, "zips_us_topo.json")
.await(ready);
function ready(error, us) {
svg.append("g")
.attr("class", "counties")
.selectAll("path")
.data(topojson.feature(us, us.objects.zip_codes_for_the_usa).features)
.enter().append("path")
.attr("class", "zip")
.attr("data-zip", function(d) {return d.properties.zip; })
.attr("data-state", function(d) {return d.properties.state; })
.attr("data-name", function(d) {return d.properties.name; })
.attr("d", path);
}
</script>
</body>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@roesler-stan

This comment has been minimized.

Copy link

commented Aug 22, 2015

Hi Jeffriesen, Thank you so much for the helpful code. Do you have any tips for how to create a .shp / .json file for a single state while keeping the zip codes as a property? I tried topojson ... -p ZIP, but I think it failed because I haven't found a proper California .shp file that includes zip code information. The zipcodes_for_the_usa file is great, but I only want California. Thanks!

@raymondberg

This comment has been minimized.

Copy link

commented Aug 26, 2015

Rockin' gist @jefffriesen

@RussRezek

This comment has been minimized.

Copy link

commented Sep 29, 2015

I was actually looking for the same thing as @roesler-stan..is there a way to easily parse this file into separate topo.json files by state?

@jlev

This comment has been minimized.

Copy link

commented Sep 29, 2015

@RussRezek and @roesler-stan I just spent several hours doing this, because I couldn't find any current open data online. Compiled and simplified topojson with makefile at https://github.com/storiesofsolidarity/us-data/tree/gh-pages/geography/zcta

Note, these are ZCTAs not actual zipcode routes.

@RussRezek

This comment has been minimized.

Copy link

commented Oct 22, 2015

Much appreciated @jlev. I'm still having trouble scaling them properly using python Vincent, but I think it has something to do with the projections that I am using. They look fine in http://mapshaper.org.

@loganrkerr

This comment has been minimized.

Copy link

commented Nov 27, 2015

Not sure if this is relevant for anyone, but I created some GeoJSON files here grouping the zip codes in @jefffriesen's TopoJSON by Metropolitan Statistical Area (MSA).

@Oscarsgc

This comment has been minimized.

Copy link

commented Jun 24, 2016

Can anybody help me? I need to get the zipcodes map, unfortunately the geocommons link is not available anymore... I need the full USA ZIP Code map, including Alaska... anybody knows how can i get it? I've been looking for that map for almost 3 weeks @jefffriesen

@oller

This comment has been minimized.

Copy link

commented Jul 7, 2016

Any luck finding anything @Oscarsgc?

In the same boat as you.. this topojson dataset is great, it's just seems to be missing Alaska (AK) and Hawaii (HI) which can be presented nicely with the albersUSA projection - as can be seen here: https://bl.ocks.org/mbostock/4060606

@priyakhokher

This comment has been minimized.

Copy link

commented Mar 15, 2017

Hi @jefffriesen,
the link for the data does not work now ! Can you update it if you know where the data is now ?

Best,
@priyakhokher

@nishadthajudeen

This comment has been minimized.

Copy link

commented Nov 20, 2017

@jefffriesen - what is your recommendation to get a latest version of zips_us_topo.json(data)?

@jefffriesen

This comment has been minimized.

Copy link
Owner Author

commented Jul 3, 2019

Hey everyone - sorry - I never saw comments on this gist until just now. Unfortunately I don't know where any updated data is now. If you find it please post it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.