From: Regina Obe Date: Tue, 14 Feb 2012 17:54:13 +0000 (+0000) Subject: #1494: documentation of new census tract loader and get_tract functions. X-Git-Tag: 2.0.0alpha5~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=35e2d0f1e0a1a46d0981fdc6941fb4c724be7f86;p=postgis #1494: documentation of new census tract loader and get_tract functions. git-svn-id: http://svn.osgeo.org/postgis/trunk@9190 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/doc/extras_tigergeocoder.xml b/doc/extras_tigergeocoder.xml index 5fe547cf9..c6985d39f 100644 --- a/doc/extras_tigergeocoder.xml +++ b/doc/extras_tigergeocoder.xml @@ -371,6 +371,54 @@ Total query runtime: 245 ms. + + + Get_Tract + + Returns census tract or field from tract table of where the geometry is located. Default to returning short name of tract. + + + + + + text get_tract + geometry loc_geom + text output_field='name' + + + + + + Description + + Given a geometry will return the census tract location of that geometry. NAD 83 long lat is assumed if no spatial ref sys is specified. + + Availability: 2.0.0 + + + + + + Examples: Basic + SELECT get_tract(ST_Point(-71.101375, 42.31376) ) As tract_name; +tract_name +--------- +1203.01 + + --this one returns the tiger geoid +SELECT get_tract(ST_Point(-71.101375, 42.31376), 'tract_id' ) As tract_id; +tract_id +--------- +25025120301 + + + + + See Also + > + + + Install_Missing_Indexes @@ -418,12 +466,12 @@ Total query runtime: 245 ms. , - + Loader_Generate_Script - Generates a shell script for the specified platform for the specified states that will download Tiger data, stage and load into tiger_data schema. Each state script is returned as a separate record. Latest version supports Tiger 2010 structural changes. + Generates a shell script for the specified platform for the specified states that will download Tiger data, stage and load into tiger_data schema. Each state script is returned as a separate record. Latest version supports Tiger 2010 structural changes and also loads census tract, block groups, and blocks tables. @@ -455,7 +503,7 @@ Total query runtime: 245 ms. loader_lookuptables each record defines a kind of table (state, county), whether to process records in it and how to load them in. Defines the steps to import data, stage data, add, removes columns, indexes, and constraints for each. Each table is prefixed with the state and inherits from a table in the tiger schema. e.g. creates tiger_data.ma_faces which inherits from tiger.faces - Availability: 2.0.0 to support Tiger 2010 structured data. + Availability: 2.0.0 to support Tiger 2010 structured data and load census tract (tract), block groups (bg), and blocks (tabblocks) tables . @@ -509,6 +557,114 @@ wget http://www2.census.gov/geo/pvs/tiger2010st/44_Rhode_Island/ --no-parent --r + + + Loader_Generate_Census_Script + + Generates a shell script for the specified platform for the specified states that will download Tiger census state tract, bg, and tabblocks data tables, stage and load into tiger_data schema. Each state script is returned as a separate record. + + + + + + setof text loader_generate_census_script + text[] param_states + text os + + + + + + Description + + Generates a shell script for the specified platform for the specified states that will download Tiger data census state tract, block groups bg, and tabblocks data tables, stage and load into tiger_data schema. Each state script is returned as a separate record. + It uses unzip on Linux (7-zip on Windows by default) and wget to do the downloading. It uses to load in the data. Note the smallest unit it does is a whole state. It will only + process the files in the staging and temp folders. + It uses the following control tables to control the process and different OS shell syntax variations. + + + + loader_variables keeps track of various variables such as census site, year, data and staging schemas + + + loader_platform profiles of various platforms and where the various executables are located. Comes with windows and linux. More can be added. + + + loader_lookuptables each record defines a kind of table (state, county), whether to process records in it and how to load them in. Defines the steps to import data, stage data, add, removes columns, indexes, and constraints for each. Each table is prefixed with the state and inherits from a table in the tiger schema. e.g. creates tiger_data.ma_faces which inherits from tiger.faces + + + Availability: 2.0.0 + includes this logic, but if you installed tiger geocoder prior to PostGIS 2.0.0 alpha5, you'll need to run this on the states you have already done + to get these additional tables. + + + + + Examples + Generate script to load up data for select states in Windows shell script format. + SELECT loader_generate_census_script(ARRAY['MA'], 'windows'); +-- result -- +set STATEDIR="\gisdata\www2.census.gov\geo\pvs\tiger2010st\25_Massachusetts" +set TMPDIR=\gisdata\temp\ +set UNZIPTOOL="C:\Program Files\7-Zip\7z.exe" +set WGETTOOL="C:\wget\wget.exe" +set PGBIN=C:\projects\pg\pg91win\bin\ +set PGPORT=5432 +set PGHOST=localhost +set PGUSER=postgres +set PGPASSWORD=yourpasswordhere +set PGDATABASE=tiger_postgis20 +set PSQL="%PGBIN%psql" +set SHP2PGSQL="%PGBIN%shp2pgsql" +cd \gisdata + +%WGETTOOL% http://www2.census.gov/geo/pvs/tiger2010st/25_Massachusetts/25/ --no-parent --relative --accept=*bg10.zip,*tract10.zip,*tabblock10.zip --mirror --reject=html +del %TMPDIR%\*.* /Q +%PSQL% -c "DROP SCHEMA tiger_staging CASCADE;" +%PSQL% -c "CREATE SCHEMA tiger_staging;" +cd %STATEDIR% +for /r %%z in (*.zip) do %UNZIPTOOL% e %%z -o%TMPDIR% +cd %TMPDIR% +%PSQL% -c "CREATE TABLE tiger_data.MA_tract(CONSTRAINT pk_MA_tract PRIMARY KEY (tract_id) ) INHERITS(tiger.tract); " +%SHP2PGSQL% -c -s 4269 -g the_geom -W "latin1" tl_2010_25_tract10.dbf tiger_staging.ma_tract10 | %PSQL% +%PSQL% -c "ALTER TABLE tiger_staging.MA_tract10 RENAME geoid10 TO tract_id; SELECT loader_load_staged_data(lower('MA_tract10'), lower('MA_tract')); " +%PSQL% -c "CREATE INDEX tiger_data_MA_tract_the_geom_gist ON tiger_data.MA_tract USING gist(the_geom);" +%PSQL% -c "VACUUM ANALYZE tiger_data.MA_tract;" +%PSQL% -c "ALTER TABLE tiger_data.MA_tract ADD CONSTRAINT chk_statefp CHECK (statefp = '25');" +: +Generate sh script +STATEDIR="/gisdata/www2.census.gov/geo/pvs/tiger2010st/25_Massachusetts" +TMPDIR="/gisdata/temp/" +UNZIPTOOL=unzip +WGETTOOL="/usr/bin/wget" +export PGBIN=/usr/pgsql-9.0/bin +export PGPORT=5432 +export PGHOST=localhost +export PGUSER=postgres +export PGPASSWORD=yourpasswordhere +export PGDATABASE=geocoder +PSQL=${PGBIN}/psql +SHP2PGSQL=${PGBIN}/shp2pgsql +cd /gisdata + +wget http://www2.census.gov/geo/pvs/tiger2010st/25_Massachusetts/25/ --no-parent --relative --accept=*bg10.zip,*tract10.zip,*tabblock10.zip --mirror --reject=html +rm -f ${TMPDIR}/*.* +${PSQL} -c "DROP SCHEMA tiger_staging CASCADE;" +${PSQL} -c "CREATE SCHEMA tiger_staging;" +cd $STATEDIR +for z in *.zip; do $UNZIPTOOL -o -d $TMPDIR $z; done +: +: + + + + + + See Also + + + + Missing_Indexes_Generate_Script