Forum OpenACS Development: ec_location_based_on_zip_code

Collapse
Posted by Torben Brosten on
Does anyone have this proc working?

..such as when adding an ecommerce customer service issue[1]

It uses table zip_codes, but I only find  us_zipcodes, which seems to be an unrelated zip table (with different field values).

Is there a package that contains zip_codes table?

Torben

1. /ecommerce/www/admin/customer-service/interaction-add-2

Collapse
Posted by Alfred Werner on
You wanna post a bug? I have some good zip databases/sources - I might be able to include something. I'm steadily chipping away at the open issues.

Thanks for all your contributions !!

Collapse
Posted by Torben Brosten on
Yeah, Thanks, Alfred.

I was hoping to find some more info before posting the bug.

This page[1] suggests that the db was available at one time from usps.gov.

Torben

1. http://www.usps.com/ncsc/addressinfo/zipcodedirectories.htm

Collapse
Posted by Torben Brosten on

Okay,this[2] database contains zip code, city and county names, which is all that ec_location_based_on_zip_code uses:

    	select state_code, city_name, county_name
      	from zip_codes

Here's the zip_codes definition:

--  ZIP_CODE                               NOT NULL VARCHAR2(10)
--  STATE_CODE                                      CHAR(2)
--  CITY_NAME                                       VARCHAR2(32)
--  COUNTY_NAME                                     VARCHAR2(32)
--  LONGITUDE                                       NUMBER(9,6)
--  LATITUDE                                        NUMBER(9,6)

The longitude and latitude seem redundant anyway, since that data is already in the us_zip_codes reference table.

Now to call 1-800-ask-usps (1-800-275-8777) for pricing, availability, and conditions for distribution.

Oh! Wait.. I get it now. The census bureau provides the same info for free via us_zip_codes, us_state_codes, and us_county_codes reference tables, which are already available via the references packages on Openacs!

Now I believe the question is, how to join these in a query so that there is not a significant delay (or load on the system).

2. http://www.usps.com/ncsc/addressinfo/citystate.htm

Collapse
Posted by Jon Griffin on
The census stuff is pretty accurate, and the problem is that when Ecommerce was ported the porters didn't use us-zipcodes et al. So a change to use the standard tables would be very useful. I updated us-zipcodes for 5.0 so the data should be as accurate as can be for free. If someone wants to donate the USPS version which cost $$$ I will be happy to add it to us-zipcodes.
Collapse
Posted by Torben Brosten on

Jon (or anyone else),

Is this an optimally formed query, considering it is a join of the 3 reference tables?

 select s.abbrev, z.name, c.name
 from us_zipcodes z, us_states s, us_counties c
 where  z.fips_state_code = s.fips_state_code and
        z.fips_county_code = c.fips_county_code and
        z.fips_state_code = c.fips_state_code and
        z.zipcode=:zip_code;

It is to replace this query for the non-existant table:

    	select state_code, city_name, county_name
      	from zip_codes
     	where zip_code=:zip_code;

Torben

Collapse
Posted by Brad Duell on
This looks ok to me.  Oracle user's might want to run the following to optimize:

create index us_counties_fips_county_ix on us_counties (fips_county_code, fips_state_code, name);

create index us_zipcodes_fips_state_ix on us_zipcodes (fips_state_code, fips_county_code, zipcode, name);

analyze table us_zipcodes compute statistics;

create index us_counties_state_abbrev_ix on us_counties (state_abbrev);

create index us_counties_fips_state_ix on us_counties (fips_state_code);

analyze table us_counties compute statistics;

Collapse
Posted by Torben Brosten on
Thanks, Brad.

I'll add these to the bug report.

https://openacs.org/bugtracker/openacs/bug?bug%5fnumber=1619

Collapse
Posted by Torben Brosten on
Looks like Don moved it over to a "bulk loading", wherever that is, i don't know.

https://openacs.org/viewcvs/openacs-4/packages/ref-us-zipcodes/sql/common/Attic/