Forum OpenACS Q&A: zip code proximity search

Collapse
Posted by tammy m on
Hi

I wanna offer a zip code proximity search on my website. Very like what is done at Greenpeace Nuclear Reactor Locator. Can anyone with experience in this give me some tips or even (gasp and quiver) some code to get me started?

tia:)

Collapse
Posted by C. R. Oldham on
We've done this--Brad Duell has the details.  I'll see if I can get him to post here or make the package we developed available.
Collapse
Posted by Chris Davies on
having looked at this for a consultant locator service, I think you are pretty much destinated for triangulation from the reference data.  I have resolved to write this after converting my database using 5.0's categories api.

Since the tiger files are imported (with some errors I might add), basically you have the zip code and the lat/long of the center point of the zip code.

From that, with a little vector math, you can take the lat/long of your subsets, and come up with a vector which can then be converted to miles or some other scalar.

Since the US is pretty small compared to the world, you could probably use some average to fix the difference in lat/long distances as you get closer to the pole.  The closer to the pole, the shorter the distance between each degree of longitude.

I don't think you could say with any great certainty the exact distance, but, you could do the vector math and determine the listings in ascending scalar length.

-- or so the theory goes.

Another way to cheat would be to take the original zip code, get the FIPS county code, and then pull any listing with a similar FIPS county code making the assumption that people won't generally go out of their county to find whatever service.  Much simpler to implement -- but people living near Washington DC can easily drive 20 minutes and reach 5 counties, 2 states and the district.

I haven't had the time to write an api to use the reference data, and haven't seen anything that does this already.  If I finish before you, I'll publish the api.

The data that is used for the Tiger files is actually a one-off project that the Census Bureau did and if I recall, is not something they have supported since 1999.

Collapse
Posted by Alfred Werner on
there are also two methods using the POINT datatype in postgres - look in the contrib directory of postgresql
Collapse
Posted by Jerry Asher on
Collapse
Posted by Jon Griffin on
The latest ref-zipcodes has 2000 updated coordinates. Unless someone wants to buy the data from the USPS and donate it to the cause, that is the best I can do for free.
Collapse
Posted by Jon Griffin on
I should clarify, the head version has the updated year 2000 data added, although again, this isn't 100% accurate at this point.
See the notes in the package.
Collapse
Posted by tammy m on
Hi again,

Thanks for all the info everyone. I emailed Brad on his honeymoon, as CR suggested, to see if what they have will work for me. That would be the best news as this seems not a trivial task.

I just ran across zipdy and wonder if that is a possibility. It is GPL'd and works on postgresql in PHP, Perl or C. Might be a good backup to look at.

How much does the 2002 census data cost?

Collapse
Posted by C. R. Oldham on
Brad used ZIPDY to build our proximity service.
Collapse
Posted by tammy m on
Yay!

I just need Brad to get back home:)

thanks so much:)

Collapse
Posted by Jerry Asher on
The sad part is that zip code proximity is not a hard task in and of itself, it's keeping current with changes in towns and zip code mappings that make it difficult.

When I compared the 1999 with the 2000 data, IIRC, I found pretty much no new zipcodes, but many new town names.

Recently I've been doing quite a bit of cross country driving and it has taken me into towns that don't exist according to the 2000 data.  The zip codes exist.  The zip codes for the most part are in the same place.  It's the name of the town that doesn't exist.  New developments like Cuesta Verde....

And to get ecommercy, which towns are likely to hold the yuppies using your service?  The new towns.  For the most part a zip-code lookup will work, but there's a reasonable chance a townname lookup will fail.

If you visit the USPS, you will find that the towns do exist as well, but it's in their please don't crawl me database.

From what I recall of the zipdy package it appears there are about 40,000 zip codes, not really all that many.  And not that many town names either.  It's a crime that the information is available online, that's it a small dataset but that they don't allow spidering it.  I once estimated less than a floppy compressed for the full dataset and just a few Kbytes to publish just diffs.

To put on a political hat, this is something a reinventing gov't administration should have released to the people (and I guess they did) and something a small business is number one kind of administration should be releasing to the people.

Very seriously, if anyone knows of a pro-bono lawyer that might be interested in this sort of thing, I would love to speak with him or her.

Collapse
Posted by Alfred Werner on
The USPS does provide this feature - http://www.uspswebtools.com ..
which allows you to do just about anything mail related you could want to. I think USPS would argue that it's not their business to provide geocoding databases - they are charged with delivering mail. That's why the previous dataset was actually from census (as is the one used for the google contest).

I've seen several posts recently about people wanting web services - maybe we as a community should tackle coding for this, Bundespost and a few others ...

Collapse
Posted by Brad Duell on
I sent the code for zipdy-openacs that James Shannon (see https://openacs.org/forums/message-view?message_id=28600) and I threw together a while back to Tammy.  No tcl or www pages, just the distance calculator and supporting cache table/procs.

This used to be in new-file-storage.  If anyone wants it, or if it's wanted in contrib in cvs then lemme know.

Collapse
Posted by Pravin Gupta on
Zipcode Finder is a comprehensive tool to find the zip code of any USA city/state. Also, users can enter their zip code to find out the cities or zip codes within a given distance from their zip code. Visit for my site and give me some topic or some code to get me started .So look for site http://www.zipcode-finder.com
Collapse
Posted by Pravin Gupta on
i have offer the search for zip code scripts availble for the my site so help the scripts code for http://www.zipcode-finder.com
Collapse
Posted by anton grey on
Nice store locator script available at http://www.php4script.com/store-locator-script/