Fun with zip codes

Noticed via Tara Calashain’s excellent ResearchBuzz, here’s a great site (maps.huge.info) that lets you view zip code outlines in Google Maps. It’s pretty addictive to type in zip codes (assuming you’re in the U.S., and you have the particular bent of mind that makes you enjoy stuff like Google Maps). For the lazy among you, here’s how it looks:
Zip codes in New York
Notice that it’s doing something cool: after you’ve typed in the first zip code, you can type in more zip codes and it will draw multiple zip codes at once.

Suppose you wanted to do stuff like this yourself. First you’d want the Google Maps API. Next, you’d need a list of all the zip codes in the U.S. This is harder than it should be. From http://www.usps.com/ncsc/faq/:

Q: Where can I get a database or directory of all ZIP Codes and/or ZIP+4 codes along with the corresponding city, state, county, etc.? Is there an FTP site for downloading?
A: The information you are seeking is not available via download but is provided through our National Customer Support Center at (800) 238-3150 ….
[and then later] The Postal Service does not maintain any ZIP Code maps. The only related product we have at this time is the TIGER/ZIP+4 File.

And “TIGER/ZIP+4 File” is a link to a 404 page. Oy, thanks a lot! Grrr. Okay, so pop on over to the U.S. Census Bureau. For example, this page has a link to many good resources, including http://www.census.gov/tiger/tms/gazetteer/zips.txt which has a list of zip codes along with the city, state, latitude, and longitude of each zip code (the lat/lon is for the zip code center).

Technically, the Census Bureau calls their data Zip Code Tabulation Areas or ZCTAs. Why? As they put it,

This new entity was developed to overcome the difficulties in precisely defining the land area covered by each ZIP Code.

For example, zip codes represent postal routes and can’t always be represented with polygons. You can almost feel the contempt seething from the Census Bureau toward the U.S. Postal Service. I can believe that when Census and Postal personnel get in the same room, arguments break out and tempers flare. Sort of like Herbert Kornfeld, the Accounts Receivable Supervisor at The Onion that is always rumbling with Accounts Payable.

Okay, where were we? Postal Service: not helpful at all. Census Bureau: a great, easy-to-parse file. Okay, how about the boundary info with the shape of a zip code/ZCTA? How about this: http://www.census.gov/geo/www/cob/zt_metadata.html Oh, snap! Census Bureau 2, Postal Service 0!

Shall we delve a little deeper? Let’s do it; zip codes are fun. By the way, if you’re not a complete and utter nerd, or you don’t have hours to kill digging into files, the huge.info site sells a DVD with cleaner data in an easier format.

Okay, let’s examine the zip code for 94043 (where Google’s headquarters are located). Go to http://www.census.gov/geo/www/cob/z52000.html#ascii and save the file for California and decompress the zip file. The files are available in three formats, but we’re sticking with straight ASCII. Inside the zip file there are two files, a tiny one and a big one. In the tiny one, look for the zip code you’re interested in (94043 in this example):

2465
“94043”
“94043”
“Z5”
“5-Digit ZCTA”

This entry means that in the big file, the zip code 94043 is represented with an ID of 2465. If you look in the big file, you’ll find the data for that polygon in latitude/longitude format:

2465 -0.122065371904532E+03 0.374225573395062E+02
-0.122077973000000E+03 0.374482390000000E+02
-0.122077373000000E+03 0.374500390000000E+02
…. ….
-0.122077973000000E+03 0.374482390000000E+02
END

The first coordinate appears to be the center of the ZCTA, so chop off the first line and the END line and put the resulting lines in a file called 94043. Now fire up gnuplot and type these commands:

set terminal png
set output "94043.png"
set nokey
set title "Zip code: 94043"
set xlabel "Longitude"
set ylabel "Latitude"
set grid
plot '94043' with lines

Alrighty, let’s see how we did. Here’s the zipcode on the original application:

Original map of 94043 zip code

And here’s our Gnuplot map:
Gnuplot plot of 94043 zip code

There’s just too many fun things to do in the world. 🙂

Update: If you enjoy playing with zip codes, Gary Price pointed me to http://www.melissadata.com/Lookups/index.htm where you can look up neat things like demographics and business counts.

55 Responses to Fun with zip codes (Leave a comment)

  1. Strangely enough, I was just looking for zipcode to town, state and back information.

    zips.txt file is neat, unfortunately outdated at least 5 years. It’s missing “new” zipcodes from both places I happened to live in in the last couple of years (both East and West coast). Makes one wonder how often they shuffle zipcodes around.

  2. Hey Matts,

    when will you extends these nice more-content containing Google maps to countries outside the US? It would be nice to get some more data for Europe. 🙂

    Tobias

  3. Particularly interesting because so much demographic data is linked to zipcodes… I’d like to see a smaller granulation but zipcodes work for many things. 🙂

  4. hey there

    I emailed Research Buzz as well, but in case you have not done multiple requests, it kicks you off after several requests (not sure how many- was not counting) and tells you to come back in 2 hours. It may be doing this via the IP since I cleared cache, cookies, history, etc and still received the same message.

  5. Michael, thanks for the pointers! Looks like that first link pre-dates the Maps API. Back then you had to use the quadtree specification, I think, instead of just giving a polyline with lat/lon coordinates. I’m glad that the API makes it easier. This stuff is just fun. 🙂

  6. Hi Matt

    And the winner is …:)

    Assuming that number of comments posted per an article represents the visitors wish to see more of the same, here are the Superstars:

    One month

    Alerting site owners to problems

    Filing a reinclusion request

    Remove result

    Data:
    ====================================

    September 2005

    UI fun: Remove result :Comments (51)

    AdWords, AdSense, and the Google blog :Comments (8)

    Alerting site owners to problems :Comments (60)

    Filing a reinclusion request :Comments (60)

    Bacon polenta :Comments (39)

    Measuring freshness :Comments (15)

    One month :Comments (72)

    Book Review: The Search :Comments (9)

    What’s an update? :Comments (34)

    ======================================

    August 2005

    Bloglines :Comments (10)

    Dashes vs. underscores :Comments (37)

    Seeing nofollow links :Comments (25)

    Smart is sexy :Comments (11)

    I do not wish my screensaver to lock my computer, thank you. :Comments (11)

    Just call me Rick :Comments (6)

    UI fun: Better queries :Comments (18)

    UI fun: Better snippets :Comments (16)

    SEO Mistakes: sneaky JavaScript :Comments (35)

    SEO Mistakes: link exchange emails :Comments (18)

    =========================================

    July 2005

    Things to do and eat in Silicon Valley :Comments (14)

    Q: Why doesn’t my site show in SafeSearch?, or “Do you hate Metallica?” :Comments (7)

    .htaccess 101: how to password protect a directory :Comments (7)

    ===============================================================

    And yes…

    “There’s just too many fun things to do in the world.” 😉

  7. Harith’s methodology, whether he realizes it or not, resembles SEO…note that Matt has to approve comments, so the true number is hidden. link: command, anyone? 😉

  8. The MAPS API is very cool. Does anyone know if there is a way to zoom in and only display the zip code and then map a specific address?

  9. Hi Matt

    When will this technology be extended into the UK? We are real interested in using this for an upcoming project thats in development stage at the moment.

  10. Sorry I forgot to add to above that will this also be available for commercial use that can be implemented into projects for www and mobile web?

    Thanks again.

  11. Matt,

    Great stuff. Maps is such a cool app that I am brainstorming for a use on our web site.

    I was reading an example that was referenced at xml.com and came across this terrific app http://www.housingmaps.com/. If you are searching for a house, as I am, it combines a few of the functions that I already use

    1. The property search
    2. The mapping of the property
    3. The photos of property)

    Awesome stuff.

    Bob L.

  12. Funny…
    ever recognized that “zip-code”, “zip code” and “zipcode” differs in google?
    I thought that “zip-code” would be stemmed to “zipcode”. But the results are different. Google is a myth 😉

    I love GoogleEarth!
    -knut

  13. Hi Matt

    Long time no blogging.

    C´mon.. say something 😉

  14. Totally fascinating now I need some time to play. Now if Google could just build me a widget that would increase my time by 100%!!!.

  15. > Makes one wonder how often they shuffle zipcodes around.

    Quite a lot, actually. I do some work with mail-list management and see evidence of this all the time. Actually, though the source escapes me at the moment, there IS somewhere with the USPS where you can get updated zip databases every month.

  16. anyone seen an example of mapping county bounderies using google map. Or should i be asking how would you go about mapping the borders of a county via google maps.

  17. In actual practice, I’ve found that the lon/lat data from the census site (gazateer) is not very accurate. For a commerical application, you’d need better data.

  18. Matt,

    I have a question for you. Can you please read this group post then reply?

    http://groups.google.com/group/google-sitemaps/browse_thread/thread/c1834900ea40e74e/8ecdca81236b6f57#8ecdca81236b6f57

    Thanks,
    Mac

  19. Think of the fun we could have in the UK if Google stepped up to provide a decent geocoder for us Google Map API fanatics

  20. wow, that is awesome, i love google maps/google local, so useful…since its release ive stopped using mapquest compeltely, its just too much better than mapquest

  21. Matt,

    I recently added both city/town and county boundary mapping to the application.

    http://maps.huge.info

    -John Coryat, author.

  22. Nice–thanks for mentioning that, John! I love plotting town boundaries..

  23. This is very cool software. I don’t think I have ever seen any kind of software draw out the area that a zipcode falls within. Pretty cool stuff.

  24. Hi Matt,

    I have just found great Google Maps site similar to this, but with whole world coverage. Maybe interesting for others as well. See http://www.maplandia.com.

    -Adam

  25. Had been playing with the tigerline database and and the geocoding and i think having it natively in your system seems costly than using the geocode us webservice.

  26. I have a list of zip codes that I want to display on Google Map (eg, with a marker – I’m not trying to show boundaries). I’d like to show them all at once, not one at a time – have you seen a site that does htis?

  27. I know this is somewhat unrelated to this thread, but I was curious as to why some addresses like this example show up as a different address when mapped by Google.

    http://maps.google.com/maps?oi=map&q=301+N+Orange+Grove+Blvd,+Pasadena,+CA+91103

    I found it odd and thought there must be an explanation????

    Thanks in advance.

    Victor

  28. Does anyone know if there is something simalar for Canada?

  29. I wish they could make that kind of map for Italy aswell. Here in Italy the companies are so lame…

  30. I wish they made smoething like this to the UK!!

  31. When does this tool will be available for another countries?

  32. multi-country zip codes would be helpfull for us as well. If anyone finds one please post.

  33. We use this tool to verify orders on our mens underwear site http://www.nuwear.com

  34. I’ve made a similar database and associated PHP class available for sale at:

    http://zip-code-boundaries.com/

    Hopefully it will be useful for companies who want ZIP Code outlines in their web applications.

  35. I have looked the web over for a site that will allow you to insert a zip code, have it mark that zip code on a map, and then save it to the map. Then be able to add another zip code and repeat the procedure. Sort of like planning a route based on zip codes, or taking a list of random zip codes and plotting them on a map. Any help would be great! am

  36. Man I wish this was available in Australia. That is such a cool tool to have especially for working out freight charges for distribution.

  37. I wish they made smoething like this to the UK!!

  38. I have a list of zip codes and I want to show their concentration on a map, kind of like a precipitation weather map. How do I do that?

  39. It helps us to keep orders from coming back as undeliverable our online store for men’s underwear ABCunderwear.com We find it very helpful

  40. I searched the regional term ‘Virginia Web Design’ and you displayed the regional results incorrectly.
    You show map tag ‘C’ as Ciniva but this should be VISIONEFX.

    The same thing happens when you search the local term ‘ Virginia Beach Web Design. You show map tag ‘A’ as Ciniva but this should be VISIONEFX.

    Why are the map tags inaccurate?

  41. The post office doesn’t provide the lists of ZIP Codes for download, but there are quite a few companies out there that are licensed to resell the data:
    http://www.zipcodedownload.com/
    http://www.greatdata.com/
    http://www.melissadata.com/

    Most of them have databases with latitude and longitude coordinates included.

  42. That’s a cool. I didn’t realize zip codes were so irregular shaped and weird looking. Check out my zip code 90211 and the craxy shaped LA zip codes arount it.

  43. I have built a set of tools to work on zip codes. Take a look at http://www.mapszipcode.com. The site is complete but I intend on adding more tools and info as time permits.

  44. This is very fun and a great application of map data with Google. Important to remind anyone doing serious analysis though, that ZCTAs are very much not “ZIP Codes”. Commercial companies (like Maponics – http://www.maponics.com – where I work) use much more accurate and current data than ZCTAs. Of course, ZIP Codes are not really polygons anyway – they are collections of houses that have the same ZIP Code, but that’s a whole other story.

  45. I was just looking for this exact tool for a blog idea I have. Managed to find this post in 10 minutes. I love the web.

  46. I would recommend http://www.zipcodesmapped.com/ for any US zip code map.
    You can use this to find any US zip code maps. You can search by (City, State OR Zip). they have all the maps showing zip codes and major mile streets in all of the united states. The service is free. Search for five Digit Zip Code and find the Maps for all 50 states. A Free ZIP Code Finder which can do wonders for you.

  47. Does anyone know of a tool that would let you enter a primary zip code and then load up a 2nd list of multiple zip codes so that you can plot them on a state, regional or US map?

    Thanks,

    Jay
    discussions@surveysquare.com

  48. You can get the free monthly updates ZIP code database from the following URL. It does not have the boundary information as mentioned by Matt earlier. However, the ZIP code list is good for validation purpose. Nothing wrong to give it a try as it is FREE.

    http://www.zipcodeworld.com/zipcodefree.htm

  49. Like Amber, I need the ability to save these (3 or 5 digit) zip code boundaries to “My Maps” in google, to track our marketing campaigns. Does anyone know if this is possible or available?

    Thanks

  50. Thanks for the census zip code link! Made my day!

  51. Definitely helps with my shipping! Thanks for the post!

  52. Hi all,

    Anyone have an idea how to combine multiple contiguous zip codes and plot an outline of the combined area >?

  53. I was looking for a site to map a bunch of addresses/zipcodes onto a Google map and found this thread.

    Here’s what I ended up using:
    http://www.batchgeo.com

    A great service with highly editable output. Exactly what I was looking for.

  54. Unfortunately when you do contact the USPS for their list of Zip codes this is the significant paragraph of the response you get back:

    The USPS offers the AMS API CD as an alternative, which has all the addressing needs on it that would have been provided through the Address API. The Address Matching System Application Programming Interface is $3,800/ annually for in-house use. This allows the customer to place the data in one location on one server and develop on one platform. If wish to develop on multiple platforms or develop software for resale, there are additional charges.

    They have an online API but you need to be a USPS shipping customer using it for that purpose in order to get the API account authorized.

    Oh well. There are other ways to get at the data.

css.php