Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
How to convert Lat/Lon to US ZIP Code?

Subject: How to convert Lat/Lon to US ZIP Code?

From: Pete sherer

Date: 6 Dec, 2010 16:40:22

Message: 1 of 6

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

Subject: How to convert Lat/Lon to US ZIP Code?

From: Sean de

Date: 6 Dec, 2010 16:59:05

Message: 2 of 6

"Pete sherer" <tsh@abg.com> wrote in message <idj3lm$rvr$1@fred.mathworks.com>...
> 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

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

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

Subject: How to convert Lat/Lon to US ZIP Code?

From: Pete sherer

Date: 6 Dec, 2010 18:20:08

Message: 3 of 6

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

Subject: How to convert Lat/Lon to US ZIP Code?

From: Sean de

Date: 6 Dec, 2010 18:46:05

Message: 4 of 6

"Pete sherer" <tsh@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
%}

Subject: How to convert Lat/Lon to US ZIP Code?

From: Alan B

Date: 6 Dec, 2010 19:19:05

Message: 5 of 6

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <idjb1d$7f7$1@fred.mathworks.com>...
> "Pete sherer" <tsh@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
> %}

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.

Subject: How to convert Lat/Lon to US ZIP Code?

From: Sami

Date: 17 Mar, 2014 03:26:07

Message: 6 of 6

"Pete sherer" wrote in message <idj3lm$rvr$1@fred.mathworks.com>...
> 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

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

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us