Direction - Creating database that will provide distance

eholtman

Registered User.
Local time
Today, 02:13
Joined
Oct 12, 2004
Messages
54
Between circuits in the same region.

Here is what I need to do, if anyone has any direction or even links to samples that would be great. I have been searching and not coming up with what I am looking for.

Basically I need to find the data circuits that are within a 10 mile radius of the location.

Fields that I have are

Address - Street - City - Zip Code. I could create a table that has all Area codes within one location. But that will be extensive since I am doing this nationwide. City or State would not work since there are several locations that are within another State.

Any direction to be able to this would be appreciated.

Thanks
 
You say that you are doing a nationwide distances table. That can be done with a little effort, but here is the catch. The 10-mile limit might not be possible. Depends on finding a particular data source you need. It has been too long since I've seen this. Anyway, here is where to start.

Go find a U.S. Postal Service web page. USPS.Gov, maybe? Do a search within site to find their ZIP-code database, which is a file you can either get sent on tape or you can download it (maybe you can... Like I said, it has been a while since I looked at this class of problem). If they offer you a ZIP+4 database and you have the +4 codes for most of your sites, you might get the resolution you wanted anyway. You might also look to the web for a general search to find a source for this information. It has been around for years.

Basically, the U.S. Postal Service ZIP database includes latitude and longitude of the geographic center (geometric centroid) of each listed ZIP code regardless of the code's shape. Now, the formula to do this excruciatingly right is a bloody train wreck involving conversion of latitude and longitude to Cartesian coordinates using one of the popular projection formulas - which are exercises in solid geometry of cones, cylinders, or pincushions - but here is an approximation you can use that is FAR easier.

You have an address including a zip-code for the site of interest and you want to find the closest circuit position to that site. OK, take the latitude and longitude of your site (from the ZIP-code list). It will be some numbers of degrees, minutes, and seconds of arc, latitude and longitude. I don't recall they go smaller than seconds of arc, but that was years ago so they might have refined it farther.

Convert these angular coordinates to seconds of arc for latitude and longitude. In each case, the formula is the same: sec-of-arc = ( 3600 * degrees ) + ( 60 * minutes ) + seconds. OR, do it the other way, in raw degrees: degr-of-arc = degrees + ( minutes/60) + (seconds/3600). Whichever you choose, BE CONSISTENT. If you want to write a formula to do this, you can write it as a VBA module. If it is declared public in a general module, you can use it in queries.

This method I'm about to tell you is correct anywhere in the USA because no part of the USA (except maybe the Aleutian islands?) crosses the international date line, which would change the sign of your longitude. If it did, you would have to "cheat" a bit to normalize the results. But for any state in the Continental USA, this works reasonably well.

For each zip-code in your list, do the same conversion to seconds of arc. You will have a latitude and a longitude. As a ROUGH approximation (and I do mean ROUGH), you can compute distance as the formula

approx. dist. = sqrt( ( (x1-x2)^2 ) + ( (y1-y2)^2 ) )

where x1 = longitude, site of interest and y1 = latitude, site of interest
and x2 = longitude, site being tested and y2 = latitude, site of interest

OK, now find the shortest approximate distance. If you make a query that does this computation, you can sort it by the computed approximate distance, smallest distance first. (I.e. sort ascending on computed distance.)

If you used degrees in your conversion, one degree at the equator is approximately 70 miles. If you used seconds in your conversion, one second is about 0.0192 miles. So the approximate distance in your angular units can be converted to linear distance by multiplying by the correct scaling factor.

NOW, for the geography purists (and for you, too), here is the reason this approximation works. IF you are lucky and have a circuit within a few miles of the site of interest, the Earth is APPROXIMATELY flat on a scale of a few miles. Enough that rounding errors make no significant difference. BUT... if the distance starts to be larger, like hundreds of miles distance, this approximation breaks down. So be warned, the farther away the two points, the worse this approximation gets.

To be excruciatingly precise, you would need better numbers for the circumference of the earth at the latitude you are using. At the equator, a degree of latitude OR longitude is 69.115 miles, based on a diameter of 7920 miles. At higher latitudes, the size of a longitude degree shrinks - but the size of a latitude degree does not (because all degrees of latitude - meridians - are on a "great circle" line, but for lines of longitude, only the equator is on a great circle.)

This means that to be precise, you would have to do trapezoidal corrections for the centroids of each zip code. Which is why you would PREFER that the points are close enough for the rectangular approximation to work. I would say that more than 1 degree of difference between the locations, anywhere in the continental USA, would be a reasonable limit for the approximation.

Be warned: If you have two or more locations that seem about the same in computed distance, the one farther NORTH is closer. That is a side effect of the trapezoid correction you would have made if you were being precise.
 

Users who are viewing this thread

Back
Top Bottom