README
1
2Installing The Tiger Geocoder
3
4This is a customized version of Steve Frost's tiger geocoder revisions.
5
6This version includes a loader that is portable between Linux and
7Windows but loads a full state of data at a time. The loader helper tables and
8functions are prefixed with loader and stored in the tiger schema. If
9you only want to load a county, revise the wget call that is generated
10for the state to just download the statewide and specific counties or
11just download them by hand. The loader will only process files that
12exist.
13
14If you are on windows, you will need 7zip and wget. 7zip you can get
15from http://www.7-zip.org/ and wget you can get from
16http://gnuwin32.sourceforge.net/packages/wget.htm
17
18Tiger Geocoder is now part of the PostGIS documentation
19for further details about function use, refer to:
20http://postgis.net/docs/manual-dev/Extras.html#Tiger_Geocoder
21
22Refer to http://postgis.net/docs/manual-dev/postgis_installation.html#install_tiger_geocoder_extension
23for installing, upgrading, and loading data from extensions.
24
25Note that installing by script approach is now deprecated, but covered in:
26http://postgis.net/docs/manual-dev/postgis_installation.html#install_tiger_geocoder
27
28Loading data:
29
301. Create a folder called gisdata on root of server or your local pc
31if you have a fast network connection to the server. This folder is
32where the tiger files will be downloaded to.
33
342. Create a folder called temp in the gisdata folder. This will be
35the folder where we extract the downloaded tiger data.
36
373. Run the following commands at psql or pgAdmin III query window to
38generate the script, replacing 'DC', 'RI' with list of states you want
39and save contents to a .bat or sh file in YOUR CURRENT DIRECTORY. This
40will generate CODE for each state and append it to the script.
41
42(IF YOU ARE AT A PSQL PROMPT, FIRST RUN "\a", "\t", AND "\o
43script.xxx". THIS WILL MAKE YOUR OUTPUT UNALIGNED AND REDIRECT IT TO
44script.xxx. WITHOUT "\a" and "\t", THE SCRIPT WILL HAVE EXTRA
45WHITESPACE AND POSSIBLY NON-SCRIPT CHARACTERS THAT CAUSE IT TO BREAK.)
46
47-- UNIX /LINUX USERS --
48-- Note even if you want just specific states you need to
49-- do this step since 2015 county, state tables are available only at national level
50SELECT loader_generate_nation_script('sh');
51
52-- After the nation load, generate a bash script suitable for Unix command lines
53-- for your desired states.
54
55SELECT loader_generate_script(ARRAY['DC','RI'], 'sh');
56
57
58ONCE YOU GENERATE THIS SCRIPT, EDIT IT TO ADD "set -e -u" AT THE TOP;
59THIS SETTING WILL MAKE IT STOP ON ERROR OR UNITIALIZED VARIABLE AND
60MAKE IT EASIER TO DEBUG ANY PROBLEMS.
61THEN RUN THE SCRIPT AT THE COMMAND LINE, REDIRECTING STANDARD OUTPUT AND
62STANDARD ERROR TO USEFUL FILES. YOU MAY WANT TO RUN "tail -f " TO SEE THE
63STANDARD ERROR AS IT GETS WRITTEN. FOR EXAMPLE:
64
65$ sh foo.sh 1>out 2>err; tail -f err
66
67-- WINDOWS USERS --
68--To generate a WINDOWS DOS script
69-- this will generate the script to download the national layers
70-- Note even if you want just specific states you need to
71-- do this step since 2011 county, state tables are available only at national level
72SELECT loader_generate_nation_script('windows');
73
74-- this you do after the nation load and for states you want
75SELECT loader_generate_script(ARRAY['DC','RI'], 'windows');
76
77If your script disappears without loading anything,
78most likely one of your path settings is wrong.
79To troubleshoot run the batch script by
80first opening up a commandline and executing the file.
81
82That will keep the window open for you to see the error.
83
84-- Next run the script to install any missing indexes --
85SELECT install_missing_indexes();
86
87Alternatively if you want to see what indexes will be created before
88you create them run the below and manually run the steps generated:
89SELECT missing_indexes_generate_script();
90
91
929. Copy and paste the generated script into a .bat or .sh file and put
93in gisdata folder you created and then run it, OR IF YOU REDIRECTED
94THE OUTPUT TO A FILE WITH "\o" MOVE THAT FILE TO GISDATA.
95
9610. Test out the geocoder run these queries
97
98-- To get the best rated answer --
99-- this is generally faster
100SELECT g.rating,
101 ST_X(geomout) As lon,
102 ST_Y(geomout) As lat, (addy).*
103FROM geocode('1731 New Hampshire Avenue Northwest, Washington, DC 20010', 1) As g;
104
105--To get multiple answers if there is more than 1
106SELECT g.rating,
107 ST_X(geomout) As lon,
108 ST_Y(geomout) As lat, (addy).*
109FROM geocode('1731 New Hampshire Avenue Northwest, Washington, DC 20010') As g;
110
111