]> granicus.if.org Git - postgis/commitdiff
#1494: documentation of new census tract loader and get_tract functions.
authorRegina Obe <lr@pcorp.us>
Tue, 14 Feb 2012 17:54:13 +0000 (17:54 +0000)
committerRegina Obe <lr@pcorp.us>
Tue, 14 Feb 2012 17:54:13 +0000 (17:54 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9190 b70326c6-7e19-0410-871a-916f4a2858ee

doc/extras_tigergeocoder.xml

index 5fe547cf9a27c887b978a9a731fe252abd29db12..c6985d39f75bb6c009ba878f1c979359733d984e 100644 (file)
@@ -371,6 +371,54 @@ Total query runtime: 245 ms.
          </refsection>
        </refentry>
        
+       <refentry id="Get_Tract">
+         <refnamediv>
+               <refname>Get_Tract</refname>
+
+               <refpurpose>Returns census tract or field from tract table of where the geometry is located. Default to returning short name of tract.</refpurpose>
+         </refnamediv>
+
+         <refsynopsisdiv>
+               <funcsynopsis>
+                 <funcprototype>
+                       <funcdef>text <function>get_tract</function></funcdef>
+                       <paramdef><type>geometry </type> <parameter> loc_geom</parameter></paramdef>
+                       <paramdef><type choice='opt'>text </type> <parameter> output_field='name'</parameter></paramdef>
+                 </funcprototype>
+               </funcsynopsis>
+         </refsynopsisdiv>
+
+         <refsection>
+               <title>Description</title>
+
+               <para>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.</para>
+
+               <para>Availability: 2.0.0</para>
+               
+         </refsection>
+
+
+         <refsection>
+               <title>Examples: Basic</title>
+               <programlisting>SELECT get_tract(ST_Point(-71.101375, 42.31376) ) As tract_name;
+tract_name
+---------
+1203.01
+               </programlisting>
+               <programlisting>--this one returns the tiger geoid
+SELECT get_tract(ST_Point(-71.101375, 42.31376), 'tract_id' ) As tract_id;
+tract_id
+---------
+25025120301</programlisting>           
+         </refsection>
+
+         <!-- Optionally add a "See Also" section -->
+         <refsection>
+               <title>See Also</title>
+               <para><xref linkend="Geocode" />></para>
+         </refsection>
+       </refentry>
+       
        <refentry id="Install_Missing_Indexes">
          <refnamediv>
                <refname>Install_Missing_Indexes</refname>
@@ -418,12 +466,12 @@ Total query runtime: 245 ms.
                <para><xref linkend="Loader_Generate_Script"/>, <xref linkend="Missing_Indexes_Generate_Script"/></para>
          </refsection>
        </refentry>
-       
+
        <refentry id="Loader_Generate_Script">
          <refnamediv>
                <refname>Loader_Generate_Script</refname>
 
-               <refpurpose>Generates a shell script for the specified platform for the specified states that will download Tiger data, stage and load into <varname>tiger_data</varname> schema. Each state script is returned as a separate record. Latest version supports Tiger 2010 structural changes.</refpurpose>
+               <refpurpose>Generates a shell script for the specified platform for the specified states that will download Tiger data, stage and load into <varname>tiger_data</varname> 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.</refpurpose>
          </refnamediv>
 
          <refsynopsisdiv>
@@ -455,7 +503,7 @@ Total query runtime: 245 ms.
             <para><varname>loader_lookuptables</varname> 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 <varname>tiger_data.ma_faces</varname> which inherits from <varname>tiger.faces</varname></para>
           </listitem>
         </orderedlist> 
-               <para>Availability: 2.0.0 to support Tiger 2010 structured data.</para>
+               <para>Availability: 2.0.0 to support Tiger 2010 structured data and load census tract (tract), block groups (bg), and blocks (tabblocks) tables .</para>
 
 
          </refsection>
@@ -509,6 +557,114 @@ wget http://www2.census.gov/geo/pvs/tiger2010st/44_Rhode_Island/ --no-parent --r
          </refsection>
        </refentry>
        
+       <refentry id="Loader_Generate_Census_Script">
+         <refnamediv>
+               <refname>Loader_Generate_Census_Script</refname>
+
+               <refpurpose>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 <varname>tiger_data</varname> schema. Each state script is returned as a separate record.</refpurpose>
+         </refnamediv>
+
+         <refsynopsisdiv>
+               <funcsynopsis>
+                 <funcprototype>
+                       <funcdef>setof text <function>loader_generate_census_script</function></funcdef>
+                       <paramdef><type>text[]</type> <parameter>param_states</parameter></paramdef>
+                       <paramdef><type>text</type> <parameter>os</parameter></paramdef>
+                 </funcprototype>
+               </funcsynopsis>
+         </refsynopsisdiv>
+
+         <refsection>
+               <title>Description</title>
+
+               <para>Generates a shell script for the specified platform for the specified states that will download Tiger data census state <varname>tract</varname>, block groups <varname>bg</varname>, and <varname>tabblocks</varname> data tables, stage and load into <varname>tiger_data</varname> schema.  Each state script is returned as a separate record.</para>
+               <para>It uses unzip on Linux (7-zip on Windows by default) and wget to do the downloading. It uses <xref linkend="shp2pgsql_usage" /> 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.</para>
+               <para>It uses the following control tables to control the process and different OS shell syntax variations.</para>
+
+               <orderedlist>
+          <listitem>
+            <para><varname>loader_variables</varname> keeps track of various variables such as census site, year, data and staging schemas</para>
+          </listitem>
+          <listitem>
+            <para><varname>loader_platform</varname> profiles of various platforms and where the various executables are located.  Comes with windows and linux. More can be added.</para>
+          </listitem>
+          <listitem>
+            <para><varname>loader_lookuptables</varname> 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 <varname>tiger_data.ma_faces</varname> which inherits from <varname>tiger.faces</varname></para>
+          </listitem>
+        </orderedlist> 
+               <para>Availability: 2.0.0 </para>
+               <note><para><xref linkend="Loader_Generate_Script" /> 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.</para></note>
+         </refsection>
+
+
+         <refsection>
+               <title>Examples</title>
+               <para>Generate script to load up data for select states in Windows shell script format.</para>
+               <programlisting>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');"
+: </programlisting>
+<para>Generate sh script</para>
+<programlisting>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
+:
+: </programlisting>
+
+         </refsection>
+
+         <!-- Optionally add a "See Also" section -->
+         <refsection>
+               <title>See Also</title>
+               <para><xref linkend="Loader_Generate_Script" /></para>
+         </refsection>
+       </refentry>
+       
        <refentry id="Missing_Indexes_Generate_Script">
          <refnamediv>
                <refname>Missing_Indexes_Generate_Script</refname>