Archive for September, 2008

Zip Code, Latitude, Longitude, City, State

Saturday, September 27th, 2008

Recently Eric Meyer asked how to translate thousands of postcodes into city and state. For large datasets, your best bet may be a commercial geocoding service. Google and the USGS both use Tele Atlas, for instance. However, if you just want something to play with, you have several options. You can pre-process your data with the 1999 U.S. Postal Service ZIP Codes and Federal Information Processing Standards (FIPS) Codes from the US Census Bureau. Use MS Access to import the zipnov99 dBase file and then export as a tab delimited text file. The result includes Zip Code, latitude, longitude, state code, county code, and a few other codes. The state and county codes match the FIPS codes, which then give you the full state and county.

You could also use the United States Zip Code Database (updated 2/99) available from Unisys Global Station Index Information. This is a National Weather Service related data product, and contains state, country, latitude, longitude, and elevation of weather stations.

To use the 1999 geocode data, I wrote a small Perl script that reads multiple data files, matches each Zip Code with the corresponding geocode data, and then outputs a single combined file.

For data visualization, I uploaded the resulting tab delimited file to a Google Spreadsheet, and then used the Google Map Wizard to output the map code. This is an easy way to put any location on a map. You can also add information and links to each marker.

What follows is a Google map for the processed California data from the 2008 Survey results. A few Zip Codes did not match the 1999 data and are not included. Please note there are nearly 2,000 data points, so there will be a delay when the data loads. Loading will also max your CPU temporarily, and the map will be a bit slow when you zoom. Here is the map demo.

If you don’t have thousands of addresses, you may be interested in geocoding addresses with PHP/MySQL instead. You may also be interested in Ben Fry’s zipdecode project, which is further described in his book, Visualizing Data.

Comments are moderated.