Plotting Surrounding Zip Codes based on Longitude & Lati

rmfrase

Board Regular
Joined
Jul 6, 2006
Messages
128
Having the Zip Code Tabulation Module from the US Census Bureau, I have the following and much more. But based on the 3 items :
5-digit Zip Code, Longitude, Latitude.

I'm wanting to Select a Zip Code and have (let's say) several Zip Codes plotted (maybe 4 - 10) out from the center point of the map.
either with, or without a connecting straight line .

And possibly a Scalable Miliage indicator |---- 10 Miles ----| which would be based on the distance.

Is this possible?

Your thoughts?

-Robert
 
Thank you all for your assistance. Now that I have the Distance between two Lat/Long points, any suggestions how I select the 5 or 10 closest locations based on Lat/Lon?

My Zip Code table consists of 32,082 rows (with Lat/Lon)
 
Upvote 0

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Well I'm working my way there, speaking for myself. I've written a sheet to calculate the distances, based on either xx yy zz format or the full floating point decimal degrees.

Please test this. The "poor man's" hypotenuse appears to be within 1% of actual up to about 2000 miles, and .03% at 400 miles. The second method is the arccosine method, presumably very accurate. The third I tried on a lark, and seems to fall apart except for short distances.

This is my world first usage of COLO so the display may not be just as it should (especially since I let long strings spill to empty cells to their right), and scraping and pasting to a blank sheet may need tweaking. Advise me with any tips.
latit.xls
ABCDEFGHIJKLMN
1latitudelongitude
2+=amtNofequatorprecise+=amtWofPrimeMprecise
3degreesminssecsdegreesradiansdegreesminssecsdegreesradians
41374615.637.7710.6592-122-24-25-122.41-2.13641(alt.inputmethod)
52374615.637.7710.6592-122-24-25-122.41-2.13641ChinatownS.F.
63374825.237.8070.6599-122-24-7.2-122.4-2.13632NorthBeach
743665E-1236.10.6301-115-9-3.6-115.15-2.00976UNLVlot
8536057.636.0160.6286-114-44-17-114.74-2.00256HooverDam
96404121.4840.68930.7102-74-2-41-74.045-1.29232StatueofLiberty
1073540-035.66670.6225139450139.752.4391Tokyo
Sheet1
 
Upvote 0
latit.xls
BCDEFGHIJKLMNOP
11FromTo
1242UNLVlottoChinatownS.F.Oneman'snauticalmile:)movable-type's
13Commoninfo:lat1lat2long1long269.16to7:
14degrees36.137.771-115.15-122Oneman'scircumference!6742miles
15radians0.630060.6592-2.0098-2.1424876
16Poorman's:
17DeltaLatDeltaLongLatMilesLongfactLongMilesdistance
18-1.6717.26-115.4755.232400.77417.069
19Exact"r*acos[sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1)]difference
20416.939-0.129819831
21http://mathforum.org/library/drmath/view/54680.html-0.03%
22phi1phi2theta1theta2c
2353.952.2-115-122.410.091642.416225.3468632
24It'sacutewayw/oradians-butbombsonlongdistances54.03%
Sheet1
 
Upvote 0
Thank you all for your help on this project.

I'm finishing up the Macro, but here are the results of my query

Putting in my target Zip Code, I'm provided a list of the closest to the target (in Miles rounded.)

2.00
3.53
4.01
4.43
4.55
5.68
5.89
6.25
6.27

My next step is placing the Target Zip in the Center of a Grid, and converting the Long/Lat of the Pulled Table and placing them in their perspective locations from the center point.

Thanks again for your help.

Robert
 
Upvote 0
Here's some thoughts about plotting the data that ponders the same things. While his formulas should be independently verified, the ideas about pixels, orientation, margins, etc. may be inspirational.

This discusses free mapmaking resources.

BTW another article noted that the Great Circle distance calculations in this thread are erroneous (beyond that already from the approximations and spherical assumption) since they disregard changes in altitude. (Oh well, some people just can't have fun.) Now that I think about it, though, the distance a plane flies from L.A. to New York is longer than the drive along the assumed sphere - it's a longer arc (so I must not be very fun either). Well, screw it; your project won't even feel it.

Keep posting. I'd like to see how this turns out.

And I STILL need guidance with HtmlMaker, in case any of you are reading this thread. I hate this screwed up scrolling like anyone else.
 
Upvote 0
Here's what I've got so far.


Target Zip Code.........Latitude.......Longitude
78572.......................26.234417...98.342059

Subject area is Rural
Surrounding area is Semi Rural

Target Population Density = ........617.83
Surrounding Area Density=........1001.57
Closest Zip Code is................78558
Closest Zip Code Density is.........438.74
Farthest Zip Code is...............78539
Farthest Zip Code Density is........201.44

Surrounding Zip Codes: Distance
78558.......................................4.90
78501.......................................6.76
78576.......................................6.78
78503.......................................7.14
78504.......................................7.17
78560.......................................9.56
78577.......................................9.94
78557.......................................10.70
78589.......................................12.12
78539.......................................12.59
***********************************
 
Upvote 0
I added to your entries the latitudes and longitudes from http://www.findzip.net/state/texas_38.html in case anyone's playing along. I did this manually and didn't check them. Later on, time permitting, I'll stick them in the spreadsheet above unless someone else (please do!) gets there first.
Code:
zip	distance	lat	long
78558	4.9	 26.294532	-98.045699
78501	6.76	26.269305	-98.224364
78576	6.78	26.193734	-98.101526
78503	7.14	26.182171	-98.33773
78504	7.17	26.326284	-98.233488
78560	9.56	26.242565	-98.474651
78577	9.94	26.186698	-98.127765
78557	10.7	26.185789	-98.272287
78589	12.12	26.214873	-98.161978
78539	12.59	26.328674	-98.139672
It appears you're going with 10 closest rather than a threshhold. Okay.

When it comes to mapping, 1. will denser urban zips crowd each other thus requiring a bigger map resolution or something? 2. have you investigated the Google map API?
 
Upvote 0
I've got it all but figured out now. The Chart will not have connecting lines, but I have been able to create as "Scatter Chart" and using VBA change the Chart Lables to Zip Codes pulled from my spread sheet.

Dim z As Integer
Dim Zip(1 To 12) As String

ActiveChart.PlotArea.Select
ActiveChart.SeriesCollection(1).DataLabels.Select
For z = 1 To 10
ActiveChart.SeriesCollection(1).Points(z).DataLabel.Select
Selection.Characters.Text = Zip(z)
Selection.AutoScaleFont = False
With Selection.Characters(Start:=1, Length:=5).Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Next
'*************

But now I have a slight Arrangement problem that I'm having trouble figuring out.

The Scatter Plot goes from 0,0 (left and bottom) up and to the right.
However, once the data is placed on the chart, the orientation is wrong (rotated.)

Suggestions?

Here are my zip codes used for testing

76137
76148
76131
76180
76117
76248
76118
76177
76106

Latitude
32.86814
32.869384
32.873017
32.855666
32.805379
32.92704
32.80533
32.949819
32.798429

Longitude
97.285666
97.251232
97.346221
97.218184
97.270367
97.250609
97.222642
97.314061
97.354004


I used this link for testing the orientation.
http://maps.huge.info/zip.htm


-Robert
 
Upvote 0
There's no need for VBA. Your problem can be solved using just Excel. Also, the reason you may be having problems with orientation is that you have your longitudes as positive values. By convention, western hemisphere longitudes are negative values.

Here's how to do it w/o VBA:

Suppose your zip code database is in H4:J{n} where H is the zip code, I the longitude, and J the latitude. Also, none of the cells H1:H3 contain any other data.

Create a named formula (Insert | Name > Define...)
ZipCodeList =OFFSET(Sheet1!$H$5,0,0,COUNTA(Sheet1!$H:$H)-1,1)

The radius of the Earth is in J1. Name that cell _R.

In H4:O4 enter the names:
Zip Code
Longitude
Latitude
Distance from ZC of interest
Closest distances
Plot Long
Plot Lat
Plot Label

Select K5 and then create the names:
_Lat1 =Sheet1!$D$5
_Lat2 =Sheet1!$J5
_Lon1 =Sheet1!$C$5
_Lon2 =Sheet1!$I5

It is important to select K5 before creating the above names since _Lat2 and _Lon2 use a *relative* row reference.

B5 will contain the zip code of interest. To make your worksheet easier to use data validation for that cell restricting entries to the named list ZipCodeList.

C5 will contain the longitude of the zip code of interest. Enter the formula =VLOOKUP(B5,OFFSET(ZipCodeList,0,0,,3),2,FALSE)

D5 will contain the latitude of the zip code of interest. Enter the formula =VLOOKUP(B5,OFFSET(ZipCodeList,0,0,,3),3,FALSE)

In E5 enter the formula =B5&CHAR(13)&" " This will be the data label on the chart to indicate the zip code of interest.

C6 will contain the number of zip codes nearest to the one of interest we want to see.

Next, in K5 enter the formula for the distance of this zip code from the one of interest =IF($H5=$B$5,0,ACOS(SIN(_Lat1)*SIN(_Lat2)+COS(_Lat1)*COS(_Lat2)*COS(_Lon2-_Lon1))*_R)

In L5 enter the array formula =IF(SUM(--(SMALL(OFFSET(ZipCodeList,0,3),ROW(INDIRECT("2:"&($C$6+1))))=K5)),K5,NA())

To complete an array formula do *not* use the ENTER key. Instead use the combination of CTRL+SHIFT+ENTER. If done correctly, Excel will show the formula enclosed in curly brackets { and }

In M5 enter =IF(ISNA($L5),NA(),I5)
In N5 enter =IF(ISNA($L5),NA(),J5)
In O5 enter =H5&CHAR(13)&" ("&ROUND(K5,0)&")"

Copy K5:O5 as far down as you have data in H:J.

Plot M:N in a XY Scatter chart. Also plot C5:D5 on the same chart as a separate series. Use O as the data label for the 1st series and E5 for the 2nd. Format the 2 series to taste.

To add the data labels either use an utility like Rob Bovey's XY Chartlabeler (www.appspro.com) or do it by hand along the lines of
Data Labels
http://www.tushar-mehta.com/excel/newsgroups/data_labels/index.html
Frankly, Rob's utility will be easier to use.

I developed the above using Excel 2007. The resulting file is at
http://www.box.net/shared/zhsih5z008 The same file, saved in the 97-2003 format, is at http://www.box.net/shared/rgxar3n6ft

The box.net service is on a as-is basis. I have no control over it and no idea of how long it will retain the above files.

I've got it all but figured out now. The Chart will not have connecting lines, but I have been able to create as "Scatter Chart" and using VBA {snip}

But now I have a slight Arrangement problem that I'm having trouble figuring out.
{snip}
-Robert
 
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top