开发者

Nearest zip code of a zip code?

开发者 https://www.devze.com 2023-01-15 20:20 出处:网络
I need to find the 5 nearest zip code of a zip code. For example, I have 33304, and I need to find the nearest ones, like 33309, 33308 ...

I need to find the 5 nearest zip code of a zip code. For example, I have 33304, and I need to find the nearest ones, like 33309, 33308 ...

Is there a database or a web service somewhere that would help me with that?

I think I'm gonna have to build my own 开发者_C百科database in order to do that? I know how to do it, but in case it has already been done ...


what country? Maybe you want to checkout Geonames: http://www.geonames.org/

Especially: http://www.geonames.org/export/web-services.html#findNearbyPostalCodes


This answer is in response to the recent bounty requesting a location of US Zip Codes.

The United States Census Bureau has a list of zip codes (with latitude and longitude) on their web site.

The zip code tabulation areas is a CSV that contains (as described in the description of the file format), among other fields:

Column 1    GEOID   Five digit ZIP Code Tabulation Area Census Code
...
Column 6    INTPTLAT    Latitude (decimal degrees) First character is blank or "-" denoting North or South latitude respectively
Column 7    INTPTLONG   Longitude (decimal degrees) First character is blank or "-" denoting East or West longitude respectively

I'd cross reference the above, with data from the Census Bureau's county business patterns CSV to get city, state and county names. This file format is described to contain (among other fields) (description is in the file you select to download):

ZIP             C       ZIP Code
NAME            C       ZIP Code Name
...
CITY            C       ZIP City Name
STABBR          C       ZIP State Abbreviation
CTY_NAME        C       ZIP County Name


Here is a free web service to do exactly what you need: http://www.zipwise.com/webservices/


I tested geonames and did not find it good enough. Test areas near your zip code and you will not find all the zipcodew. These have good results but have not found any API yet http://www.searchbug.com/tools/zip-radius.aspx


For the nearest ZIP Code, there are two approaches: find contiguous (adjoining) ZIP Codes and/or find the nearest ZIPs based on the distance from the center of one ZIP Code to the center of another, based on latitude and longitude.

To choose the contiguous ZIP approach, you will need ZIP Code Boundaries data. Alignstar makes one that we're very pleased with (we resell it), but ESRI and a couple of other companies have good products as well. My company, GreatData.com, developed a contiguous counties product and could develop a contiguous ZIP Codes product, but so far, nobody has been asking for it. This could be a data file or an API.

To find the nearest ZIP Codes based on centroids (latitude / longitude center points of the ZIP Code), you will need a ZIP Code Database with latitude / longitude data (we provide one, or go here for links to some free resources: //http://uszipcodes.com/free-zip-code-lookup.htm. If you just want an API and not the hassle of doing it yourself, let us know. We've started to develop similar APIs and will develop based on the demand.

One caveat of doing this by the centroids: we've seen in the past where if you have a large (or long), adjoining ZIP, the center of that ZIP could be farther away than another small ZIP Code, so your list of the 5 nearest could miss an adjoining ZIP.


PostgreSQL has new feature in 9.1 called "KNN". It is specifically for "Nearest Neighbor" distance searches, and from benchmarking and testing it it myself, it is very fast, and can be used for zipcodes. Here is a quick introduction to KNN.

You can also find a thread about applying KNN to zipcodes, and a more recent follow-up.

0

精彩评论

暂无评论...
验证码 换一张
取 消