[Chilidog.com!] [The

Zip Codes, Distances, GPS and GNIS


Last updated 6/29/98
Here we have my work, discoveries, and thoughts on how to do database proximity lookups, and other fun topics on the theme.

I want to know where a zip code is:

There is no official mapping of zip codes to latitude and longitudes. Zip codes are, in fact, fabulously unconnected with any other manifestation of a physical reality than (surprise) US Postal service delivery requirements.

With that said, you have a number of options. The easiest is to fork out about $150 bucks to Zip*Data or other vendors (I will add links...) for a geo coded zip code database.

The Zip*Data product includes a useful manual along with code samples to calculate the distance between two latitude/longitude pairs.

The next easiest, and less precise, option is to download the zip code database that the Census Bureau created as a side effect of one or another of their enumerative fantasies.

The simplest option is to download this compilation zip code database (click to learn more).

All of these options will give you a convenient database of zipcodes, along with the city, state, and latitude and longitude for that zip code.

What? I can hear the clamor already. How can we have a latitude and longitude when zip codes are really quite irrational in regards to any other geographical meaning. Well...we get a 'centroid' of the zip code. Simplified painfully (in part because I find the explanation painful) the lat/long provided is an approximation based on the area covered by the zip code. Theoretically this is the 'center' of the zip code. In practice, this is a useful, but by no means precise, value to use as a starting poing for more refined calculations.

Thanks for telling me where that zip code is, now how far is it to another zip code?

Assuming everything is in radians then I believe that this formula is at least passably close to correct.

distance = acos(sin(lat1)*sin(lat2)+cos(lat1)*

cos(lat2)*cos(long2-long1))

* r

Where r is the radius of the earth in whatever units you desire.

r=3437.74677 &&statute miles

r=6378 &&kilometers

r=3963 &&normal miles

In Foxpro or dbase try this:

d=acos(sin(dtor(lat1))*sin(dtor(lat2))+cos(dtor(lat1))* ; cos(dtor(lat2))*cos(dtor(long2)-dtor(long1))) ; * r

DTOR() is the Degrees to Radians function. ACOS() is arc cosine, sin and cos should be obvious (if not, just enter it the way I wrote it and you shouldn't be far off, or, better yet :-), hire me as a consultant to set it up for you).

What other fun things can I do?

The United States Geological Survey has the official United States 'Geographic Names Information System' database available online, and available for anonymous ftp download.

The GNIs contains the names of over 2 million 'things,' along with the 'type' of thing, the location of the thing (state, county, and lat/long) and some other fun information for many of the 'things.' A 'thing' is just about anything that appears on a government map (USGS topos, forest service, FAA charts, etc) that is not a road.

Using the GNIS, your GPS, and a bit of software ingenuity you can get answers to such pressing questions as "I am in the middle of nowhere, what am I close to?" or "What is that mountain over there?

The GNIS is _very_ cool!

Chilidog home!