Zip Code Index OT

J

Jeff Thies

I need to do a distance from zipcode kind of lookup.

Anyone know where there might be free to cheap zip tables (with the geo
co-ordinates)?

Jeff
 
M

mscir

Jeff said:
I need to do a distance from zipcode kind of lookup.

Anyone know where there might be free to cheap zip tables (with the geo
co-ordinates)?

Jeff

US Census Bureau has free 1/1/2000 data here:

http://www.census.gov/geo/www/gazetteer/places2k.html

The place file contains data for all Incorporated and Census Designated
places in the 50 states, the District of Columbia and Puerto Rico as of
the January 1, 2000. The file is plain ASCII text, one line per record.

* Columns 1-2: United States Postal Service State Abbreviation
* Columns 3-4: State Federal Information Processing (FIPS) code
* Columns 5-9: Place FIPS Code
* Columns 10-73: Name
* Columns 74-82: Total Population (2000)
* Columns 83-91: Total Housing Units (2000)
* Columns 92-105: Land Area (square meters)
* Columns 106-119: Water Area(square meters)
* Columns 120-131: Land Area (square miles)
* Columns 132-143: Water Area (square miles)
* Columns 144-153: Latitude (decimal degrees)
* Columns 154-164: Longitude (decimal degrees)

ASCII text versions of:
* Places: 3MB

FTP compressed versions of:
* Places.zip: 1MB

If you're calculating distance between 2 locations using lat/long, can I
ask how you're calculating it? I've seen several equations that do that,
including finding great circle distance.

Mike
 
D

Dennis M. Marks

Jeff said:
I need to do a distance from zipcode kind of lookup.

Anyone know where there might be free to cheap zip tables (with the geo
co-ordinates)?

Jeff
Look up "distance between zip codes" in Google. It has already been
done. Maybe you can use an existing calculator.
 
J

Jeff Thies

Hi Mike,

Comments embedded.
US Census Bureau has free 1/1/2000 data here:

http://www.census.gov/geo/www/gazetteer/places2k.html

Thanks! I used the ZCTA file on this page instead. THe census code didn't
have the zip codes.
The place file contains data for all Incorporated and Census Designated
places in the 50 states, the District of Columbia and Puerto Rico as of
the January 1, 2000. The file is plain ASCII text, one line per record.

* Columns 1-2: United States Postal Service State Abbreviation
* Columns 3-4: State Federal Information Processing (FIPS) code
* Columns 5-9: Place FIPS Code
* Columns 10-73: Name
* Columns 74-82: Total Population (2000)
* Columns 83-91: Total Housing Units (2000)
* Columns 92-105: Land Area (square meters)
* Columns 106-119: Water Area(square meters)
* Columns 120-131: Land Area (square miles)
* Columns 132-143: Water Area (square miles)
* Columns 144-153: Latitude (decimal degrees)
* Columns 154-164: Longitude (decimal degrees)

ASCII text versions of:
* Places: 3MB

FTP compressed versions of:
* Places.zip: 1MB

If you're calculating distance between 2 locations using lat/long, can I
ask how you're calculating it? I've seen several equations that do that,
including finding great circle distance.

The project is to sort office locations by distance from users zipcode. I
don't think that requires much accuracy (and the distance from postoffice is
unknow) so I thought:

1) I'd calculate latitude and longitude miles/degree for the reference
location

2) Just use a straightup euclidan calc in the database sql:

((lat_ref-lat_location)*(miles/lat_degree)) *
((longitude_ref-longitude_location)*(miles/longitude_degree))

and sort by that

Perl to do mileage is:

use POSIX qw{acos};

sub convertLatitudeLongitudeToMiles{
($lat1, $lon1, $lat2, $lon2)=@_;
$dist = acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2)));

$dist = rad2deg($dist);
return $miles = $dist * 69;
}

sub deg2rad{
my $deg=shift;
return (2 * pi *$deg/360);
}

sub rad2deg{
my $rad=shift;
return ($rad * 360/( 2 * pi));
}

Don't know if that is great circle or not! I didn't work out the trig behind
that.

Got a better idea?

Cheers,
Jeff
 
M

mscir

Jeff said:
Hi Mike,


The project is to sort office locations by distance from users zipcode. I
don't think that requires much accuracy (and the distance from postoffice is
unknow) so I thought:

1) I'd calculate latitude and longitude miles/degree for the reference
location

2) Just use a straightup euclidan calc in the database sql:

((lat_ref-lat_location)*(miles/lat_degree)) *
((longitude_ref-longitude_location)*(miles/longitude_degree))

and sort by that

Perl to do mileage is:

use POSIX qw{acos};

sub convertLatitudeLongitudeToMiles{
($lat1, $lon1, $lat2, $lon2)=@_;
$dist = acos(sin(deg2rad($lat1)) * sin(deg2rad($lat2)) +
cos(deg2rad($lat1)) * cos(deg2rad($lat2)) * cos(deg2rad($lon1 - $lon2)));

$dist = rad2deg($dist);
return $miles = $dist * 69;
}

sub deg2rad{
my $deg=shift;
return (2 * pi *$deg/360);
}

sub rad2deg{
my $rad=shift;
return ($rad * 360/( 2 * pi));
}

Don't know if that is great circle or not! I didn't work out the trig behind
that.

Got a better idea?
Cheers,
Jeff

No, I was just curious after looking at various approaches found with
Google.

Thanks,
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,177
Latest member
OrderGlucea
Top