Skip to content

Commit

Permalink
Merge pull request #12 from kashif/tiger-2013
Browse files Browse the repository at this point in the history
use the tiger 2013 geocoding sql and add -D option to shp2psql loader
  • Loading branch information
robe2 committed Sep 22, 2013
2 parents 4fd0ad9 + 7c00420 commit 1fbdd10
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion extras/tiger_geocoder/tiger_2011/create_geocode.bat
Expand Up @@ -15,7 +15,7 @@ REM "%PGBIN%\psql" -d "%THEDB%" -c "ALTER DATABASE %THEDB% SET search_path=publi
"%PGBIN%\psql" -d "%THEDB%" -f "create_geocode.sql"
REM "%PGBIN%\psql" -d "%THEDB%" -f "tables\lookup_tables_2011.sql"
"%PGBIN%\psql" -d "%THEDB%" -c "CREATE SCHEMA tiger_data;"
"%PGBIN%\psql" -d "%THEDB%" -f "tiger_loader_2012.sql;"
"%PGBIN%\psql" -d "%THEDB%" -f "tiger_loader_2013.sql;"
"%PGBIN%\psql" -d "%THEDB%" -f "census_loader.sql;"
"%PGBIN%\psql" -d "%THEDB%" -c "SELECT tiger.create_census_base_tables();"
"%PGBIN%\psql" -d "%THEDB%" -c "CREATE INDEX idx_tiger_addr_least_address ON addr USING btree (least_hn(fromhn,tohn));"
Expand Down
2 changes: 1 addition & 1 deletion extras/tiger_geocoder/tiger_2011/create_geocode.sh
Expand Up @@ -16,7 +16,7 @@ ${PSQL_CMD} -d "${THEDB}" -c "CREATE SCHEMA tiger"
#${PSQL_CMD} -d "${THEDB}" -f "tables/lookup_tables_2010.sql"
${PSQL_CMD} -d "${THEDB}" -c "CREATE SCHEMA tiger_data"
${PSQL_CMD} -d "${THEDB}" -f "create_geocode.sql"
${PSQL_CMD} -d "${THEDB}" -f "tiger_loader_2012.sql"
${PSQL_CMD} -d "${THEDB}" -f "tiger_loader_2013.sql"
${PSQL_CMD} -d "${THEDB}" -f "census_loader.sql"
${PSQL_CMD} -d "${THEDB}" -c "SELECT tiger.create_census_base_tables();"
${PSQL_CMD} -d "${THEDB}" -c "CREATE INDEX idx_tiger_addr_least_address ON addr USING btree (least_hn(fromhn,tohn));"
Expand Up @@ -52,7 +52,7 @@ BEGIN
part := 0.5;
END IF;

center_pt = ST_Line_Interpolate_Point(road, part);
center_pt = ST_LineInterpolatePoint(road, part);
IF in_side > '' AND in_offset_m > 0 THEN
/** Compute point the point to the in_side of the geometry **/
/**Take into consideration non-straight so we consider azimuth
Expand All @@ -66,7 +66,7 @@ BEGIN
This will be the start of our azimuth calc **/
SELECT i INTO npos
FROM generate_series(1,ST_NPoints(road)) As i
WHERE part > ST_Line_Locate_Point(road,ST_PointN(road,i))
WHERE part > ST_LineLocatePoint(road,ST_PointN(road,i))
ORDER BY i DESC;
IF npos < ST_NPoints(road) THEN
az := ST_Azimuth (ST_PointN(road,npos), ST_PointN(road, npos + 1));
Expand Down
Expand Up @@ -166,7 +166,7 @@ BEGIN
var_addy.address := var_nstrnum;
IF var_redge.fromhn IS NOT NULL THEN
--interpolate the number -- note that if fromhn > tohn we will be subtracting which is what we want
var_nstrnum := (var_redge.fromhn + ST_Line_Locate_Point(var_redge.line, var_pt)*(var_redge.tohn - var_redge.fromhn))::numeric(10);
var_nstrnum := (var_redge.fromhn + ST_LineLocatePoint(var_redge.line, var_pt)*(var_redge.tohn - var_redge.fromhn))::numeric(10);
-- The odd even street number side of street rule
IF (var_nstrnum % 2) != (var_redge.tohn % 2) THEN
var_nstrnum := CASE WHEN var_nstrnum + 1 NOT BETWEEN var_redge.fromhn AND var_redge.tohn THEN var_nstrnum - 1 ELSE var_nstrnum + 1 END;
Expand Down
6 changes: 3 additions & 3 deletions extras/tiger_geocoder/tiger_2011/tiger_loader_2011.sql
Expand Up @@ -80,7 +80,7 @@ cd ${staging_fold}
%PSQL% -c "CREATE SCHEMA ${staging_schema};"
for /r %%z in (*.zip) do %UNZIPTOOL% e %%z -o%TMPDIR%
cd %TMPDIR%', E'%PSQL%', E'\\', E'%SHP2PGSQL%', 'set ',
'for /r %%z in (*${table_name}.dbf) do (${loader} -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
'for /r %%z in (*${table_name}.dbf) do (${loader} -D -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
);


Expand All @@ -106,7 +106,7 @@ for z in *.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
for z in */*.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
cd $TMPDIR;\n', '${PSQL}', '/', '${SHP2PGSQL}', 'export ',
'for z in *${table_name}.dbf; do
${loader} -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${loader} -D -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${PSQL} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));"
done');

Expand Down Expand Up @@ -179,7 +179,7 @@ VALUES(4, 'zcta5', 'zcta510', true,true, false,false, false, 'a',
'${psql} -c "CREATE TABLE ${data_schema}.${state_abbrev}_${lookup_name}(CONSTRAINT pk_${state_abbrev}_${lookup_name} PRIMARY KEY (zcta5ce,statefp), CONSTRAINT uidx_${state_abbrev}_${lookup_name}_gid UNIQUE (gid)) INHERITS(${lookup_name});" ',
'${psql} -c "ALTER TABLE ${data_schema}.${state_abbrev}_${lookup_name} ADD CONSTRAINT chk_statefp CHECK (statefp = ''${state_fips}'');"
${psql} -c "CREATE INDEX ${data_schema}_${state_abbrev}_${lookup_name}_the_geom_gist ON ${data_schema}.${state_abbrev}_${lookup_name} USING gist(the_geom);"'
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2010/ZCTA5/2010');
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2011/ZCTA5/2011');


INSERT INTO loader_lookuptables(process_order, lookup_name, table_name, load, level_county, level_state, single_geom_mode, insert_mode, pre_load_process, post_load_process )
Expand Down
6 changes: 3 additions & 3 deletions extras/tiger_geocoder/tiger_2011/tiger_loader_2012.sql
Expand Up @@ -95,7 +95,7 @@ cd ${staging_fold}
%PSQL% -c "DO language ''plpgsql'' $$ BEGIN IF NOT EXISTS (SELECT * FROM information_schema.schemata WHERE schema_name = ''${data_schema}'' ) THEN CREATE SCHEMA ${data_schema}; END IF; END $$"
for /r %%z in (*.zip) do %UNZIPTOOL% e %%z -o%TMPDIR%
cd %TMPDIR%', E'%PSQL%', E'\\', E'%SHP2PGSQL%', 'set ',
'for /r %%z in (*${table_name}.dbf) do (${loader} -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
'for /r %%z in (*${table_name}.dbf) do (${loader} -D -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
);


Expand All @@ -120,7 +120,7 @@ for z in *.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
for z in */*.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
cd $TMPDIR;\n', '${PSQL}', '/', '${SHP2PGSQL}', 'export ',
'for z in *${table_name}.dbf; do
${loader} -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${loader} -D -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${PSQL} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));"
done');

Expand Down Expand Up @@ -208,7 +208,7 @@ VALUES(4, 'zcta5', 'zcta510', true,true, false,false, false, 'a',
'${psql} -c "CREATE TABLE ${data_schema}.${state_abbrev}_${lookup_name}(CONSTRAINT pk_${state_abbrev}_${lookup_name} PRIMARY KEY (zcta5ce,statefp), CONSTRAINT uidx_${state_abbrev}_${lookup_name}_gid UNIQUE (gid)) INHERITS(${lookup_name});" ',
'${psql} -c "ALTER TABLE ${data_schema}.${state_abbrev}_${lookup_name} ADD CONSTRAINT chk_statefp CHECK (statefp = ''${state_fips}'');"
${psql} -c "CREATE INDEX ${data_schema}_${state_abbrev}_${lookup_name}_the_geom_gist ON ${data_schema}.${state_abbrev}_${lookup_name} USING gist(the_geom);"'
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2010/ZCTA5/2010');
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2012/ZCTA5/2012');


INSERT INTO loader_lookuptables(process_order, lookup_name, table_name, load, level_county, level_state, single_geom_mode, insert_mode, pre_load_process, post_load_process )
Expand Down
6 changes: 3 additions & 3 deletions extras/tiger_geocoder/tiger_2011/tiger_loader_2013.sql
Expand Up @@ -95,7 +95,7 @@ cd ${staging_fold}
%PSQL% -c "DO language ''plpgsql'' $$ BEGIN IF NOT EXISTS (SELECT * FROM information_schema.schemata WHERE schema_name = ''${data_schema}'' ) THEN CREATE SCHEMA ${data_schema}; END IF; END $$"
for /r %%z in (*.zip) do %UNZIPTOOL% e %%z -o%TMPDIR%
cd %TMPDIR%', E'%PSQL%', E'\\', E'%SHP2PGSQL%', 'set ',
'for /r %%z in (*${table_name}.dbf) do (${loader} -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
'for /r %%z in (*${table_name}.dbf) do (${loader} -D -s 4269 -g the_geom -W "latin1" %%z tiger_staging.${state_abbrev}_${table_name} | ${psql} & ${psql} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));")'
);


Expand All @@ -120,7 +120,7 @@ for z in *.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
for z in */*.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done
cd $TMPDIR;\n', '${PSQL}', '/', '${SHP2PGSQL}', 'export ',
'for z in *${table_name}.dbf; do
${loader} -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${loader} -D -s 4269 -g the_geom -W "latin1" $z ${staging_schema}.${state_abbrev}_${table_name} | ${psql}
${PSQL} -c "SELECT loader_load_staged_data(lower(''${state_abbrev}_${table_name}''), lower(''${state_abbrev}_${lookup_name}''));"
done');

Expand Down Expand Up @@ -208,7 +208,7 @@ VALUES(4, 'zcta5', 'zcta510', true,true, false,false, false, 'a',
'${psql} -c "CREATE TABLE ${data_schema}.${state_abbrev}_${lookup_name}(CONSTRAINT pk_${state_abbrev}_${lookup_name} PRIMARY KEY (zcta5ce,statefp), CONSTRAINT uidx_${state_abbrev}_${lookup_name}_gid UNIQUE (gid)) INHERITS(${lookup_name});" ',
'${psql} -c "ALTER TABLE ${data_schema}.${state_abbrev}_${lookup_name} ADD CONSTRAINT chk_statefp CHECK (statefp = ''${state_fips}'');"
${psql} -c "CREATE INDEX ${data_schema}_${state_abbrev}_${lookup_name}_the_geom_gist ON ${data_schema}.${state_abbrev}_${lookup_name} USING gist(the_geom);"'
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2010/ZCTA5/2010');
, ARRAY['gid','geoid','geoid10'], 'ftp://ftp2.census.gov/geo/tiger/TIGER2013/ZCTA5/2013');


INSERT INTO loader_lookuptables(process_order, lookup_name, table_name, load, level_county, level_state, single_geom_mode, insert_mode, pre_load_process, post_load_process )
Expand Down
2 changes: 1 addition & 1 deletion extras/tiger_geocoder/tiger_2011/upgrade_geocoder.bat
Expand Up @@ -10,7 +10,7 @@ set PGCONTRIB=C:\Program Files\PostgreSQL\8.4\share\contrib

REM unremark the loader line to update your loader scripts
REM note this wipes out your custom settings in loader_* tables
REM "%PGBIN%\psql" -d "%THEDB%" -f "tiger_loader_2012.sql"
REM "%PGBIN%\psql" -d "%THEDB%" -f "tiger_loader_2013.sql"
cd regress
REM "%PGBIN%\psql" -d "%THEDB%" -t -f regress.sql
pause
Expand Down
2 changes: 1 addition & 1 deletion extras/tiger_geocoder/tiger_2011/upgrade_geocoder.sh
Expand Up @@ -11,4 +11,4 @@ ${PSQL_CMD} -d "${THEDB}" -f "upgrade_geocode.sql"

#unremark the loader line to update your loader scripts
#note this wipes out your custom settings in loader_* tables
#${PSQL_CMD} -d "${THEDB}" -f "tiger_loader_2012.sql"
#${PSQL_CMD} -d "${THEDB}" -f "tiger_loader_2013.sql"

0 comments on commit 1fbdd10

Please sign in to comment.