Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert Lat/Lon to US ZIP Code?

58 views
Skip to first unread message

Pete sherer

unread,
Dec 6, 2010, 11:40:22 AM12/6/10
to
Hi,

I have a set of Lat/Lon pairs about 8000 pairs. I would like to identify/convert them into the US zip code. Is there a way to do this? I don't have the ZIP code polygon.

Thanks,
Pete

Sean de

unread,
Dec 6, 2010, 11:59:05 AM12/6/10
to
"Pete sherer" <t...@abg.com> wrote in message <idj3lm$rvr$1...@fred.mathworks.com>...

How about this?
http://www.boutell.com/zipcodes/

Then you'd just have to find the basin the given lat/lon falls in.

Pete sherer

unread,
Dec 6, 2010, 1:20:08 PM12/6/10
to
Does Matlab ave the zip code boundary file?
Without the boundary, I can't locate coordinates.

Sean de

unread,
Dec 6, 2010, 1:46:05 PM12/6/10
to
"Pete sherer" <t...@abg.com> wrote in message <idj9go$pm0$1...@fred.mathworks.com>...

> Does Matlab ave the zip code boundary file?
> Without the boundary, I can't locate coordinates.

I don't know but that website that I gave you does. Look at the CSV file, the first column is zip code, then the 4th/5th are lat and lon.

Thus you could load that in and do the whole operation on it at once using BSXFUN. Here's an example:
ll = [40.1 30.2]; %desired lat and lon
[lat lon] = meshgrid(20:.1:45,20:.1:45); %all combos (the web list has this already!)
tbl = [lat(:) lon(:)]; %combined for bsxfun
[junk, idx] = min(sum(bsxfun(@(x,y)abs(x-y),ll,tbl),2)); %minimum absolute difference

idx will be the row containing the answer.
tbl(idx,:)
%{
ans = 40.1 30.2
%}

Alan B

unread,
Dec 6, 2010, 2:19:05 PM12/6/10
to
"Sean de " <sean.d...@nospamplease.umit.maine.edu> wrote in message <idjb1d$7f7$1...@fred.mathworks.com>...

Zip codes are not points, they are polygons, and frequently very irregular polygons. I'm not sure how you can get accurate answers with this. A simple example where it will fail: an AxB rectangle adjacent to a BxC rectangle, where A>C - points inside the AxB region but near the boundary are closer to the centroid of the BxC region.

Sami

unread,
Mar 16, 2014, 11:26:07 PM3/16/14
to
"Pete sherer" wrote in message <idj3lm$rvr$1...@fred.mathworks.com>...
Hi Pete.

Please see the link below, I have uploaded a file will do this for you!
http://www.mathworks.com/matlabcentral/fileexchange/45905-zip-code-latitude-longitude-city-state-county

Regards,
Sami
0 new messages