<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.8.0">
</HEAD>
<BODY>
Hello All,<BR>
<BR>
I am looking for anyone (company or individual) who has data consisting of zip codes, carrier routes, and the geometries for each carrier route.&nbsp; I currently have the USPS TIGER/ZIP+4 product to match USPS carrier routes to TIGER/line records by TLID, but alas, it is missing over 15000 zip codes worth of data.&nbsp; What I am doing is allowing the user to input an address and one or more radii in miles and I am returning the demographics associated with the resulting region of interest.&nbsp; I have all the geocoding complete and all the demographics at the carrier route level complete, but what I'm missing is the in-between step of determining which carrier routes apply to the ROI by using PostGIS functions on the carrier route geometries.&nbsp; Of course this is only a problem for the missing zip codes all others work great.&nbsp; I am also open to other forms of calculating these values such as using census block/tract geometries to match against ROI, percetange of ZCTA covered by ROI, etc. and if anyone has any advice or suggestions they are warmly welcomed.<BR>
<BR>
I could also really use some advice on how to make these functions below the most efficient.&nbsp; 
<PRE>
create or replace function <A HREF="http://localhost/%7Emark/phpPgAdmin-4.0.1/redirect.php?server=%3A5432&database=tiger&schema=public&function_oid=17039&subject=function&function=getdemographicsbyaddress+%28text%2C+numeric%29">getdemographicsbyaddress (text, numeric)</A> returns setof demographics as $$
declare
    g geometry;
    e geometry;
    rec record;
    d demographics;
begin
&nbsp;&nbsp;&nbsp; --returns polygon resulting from buffing point geometry result of geocode function by $2 miles
    select getBufferedGeometry(geocode($1),$2) into g;
    select Envelope(g) into e;
    for rec in (
        select distinct(zipcode)
        from usps_tiger_zipplus4
        where geom &amp;&amp; e
            and Intersects(geom,g)
        order by zipcode
    ) loop
        select * from getDemographicsByAddress(rec.zipcode,g,e) into d;
        return next d;
    end loop;
    return;
end;
$$ language plpgsql;

create or replace function <A HREF="http://localhost/%7Emark/phpPgAdmin-4.0.1/redirect.php?server=%3A5432&database=tiger&schema=public&function_oid=17039&subject=function&function=getdemographicsbyaddress+%28text%2C+numeric%29">getdemographicsbyaddress (varchar, geometry,</A> geometry<A HREF="http://localhost/%7Emark/phpPgAdmin-4.0.1/redirect.php?server=%3A5432&database=tiger&schema=public&function_oid=17039&subject=function&function=getdemographicsbyaddress+%28text%2C+numeric%29">)</A> returns demographics as $$
declare
    d demographics;
begin
    select * from getDemographicsByZip($1) into d;
    select sum(homes), sum(apts), sum(businesses)
        into d.homes, d.apts, d.businesses
    from carrier_route_address_totals
    where zipcode = $1
        and carrierroute in (
            select distinct(carrierroute)
            from usps_tiger_zipplus4
            where geom &amp;&amp; $3
                and Intersects(geom,$2)
                and zipcode = $1
        );
    return d;
end;
$$ language plpgsql;

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Table &quot;public.usps_tiger_zipplus4&quot;
&nbsp;&nbsp;&nbsp; Column&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Modifiers
--------------+-----------------------+-----------
 zipcode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | character varying(5)&nbsp; |
 tlid&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | character varying(10) |
 carrierroute | character varying(4)&nbsp; |
 geom&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | geometry&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | not null
Indexes:
&nbsp;&nbsp;&nbsp; &quot;idx_geom_usps_tiger_zipplus4&quot; gist (geom)
Check constraints:
&nbsp;&nbsp;&nbsp; &quot;enforce_dims_wkb_geometry&quot; CHECK (ndims(geom) = 2)
&nbsp;&nbsp;&nbsp; &quot;enforce_geotype_wkb_geometry&quot; CHECK (geometrytype(geom) = 'POLYGON'::text OR geom IS NULL)
&nbsp;&nbsp;&nbsp; &quot;enforce_srid_wkb_geometry&quot; CHECK (srid(geom) = 32767)

&nbsp;&nbsp; Table &quot;public.carrier_route_address_totals&quot;
&nbsp;&nbsp;&nbsp; Column&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Type&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Modifiers
--------------+----------------------+-----------
 zipcode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | character varying(5) | not null
 carrierroute | character varying(4) | not null
 homes&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
 apts&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
 businesses&nbsp;&nbsp; | integer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; |
Indexes:
&nbsp;&nbsp;&nbsp; &quot;carrier_route_address_totals_zipcode&quot; btree (zipcode)

</PRE>
If any more info is needed I'm happy to share.<BR>
<BR>
Thanks!<BR>
<BR>
<TABLE CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
<TR>
<TD>
Mark Thomas<BR>
<I>Sun Certified Java 5 Programmer</I><BR>
<I>Sun Certified Java 2 Programmer</I><BR>
<I>Sun Certified Web Component Developer</I>
</TD>
</TR>
</TABLE>
</BODY>
</HTML>