postgis/extras/tiger_geocoder
Regina Obe 58b3f2340f Prefer street segments that have a street name
and address range over those missing either piece,
as long as they are within 70 meters of reference point
References #5331 for PostGIS 3.4.0
2023-01-27 19:35:11 -05:00
..
geocode Prefer street segments that have a street name 2023-01-27 19:35:11 -05:00
legacy_import/tiger2008 Standardize shebangs 2020-07-01 11:00:58 +02:00
normalize Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
pagc_normalize Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
regress Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tables Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
topology Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
utility Change signature 2022-06-14 17:23:00 -04:00
COPYING Add license info to tiger_geocoder code 2018-07-21 17:53:21 +00:00
create_geocode.bat Fix issue with loading tabblock 2019-09-28 02:52:11 +00:00
create_geocode.sh Standardize shebangs 2020-07-01 11:00:58 +02:00
create_geocode.sql Geocoder enhancements, add zip4 and address_alphanumeric, adjustments to pagc matching 2017-07-27 16:19:13 +00:00
geocode_settings.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
README fix typo in instructions 2015-11-30 16:11:51 +00:00
tiger_loader_2011.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2012.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2013.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2014.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2015.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2016.sql Formatting: remove trailing whitespace from .sql files. 2018-01-17 20:39:03 +00:00
tiger_loader_2017.sql add trailing quotes to malformed statements 2020-01-02 14:10:23 -05:00
tiger_loader_2018.sql add trailing quotes to malformed statements 2020-01-02 14:10:23 -05:00
tiger_loader_2019.sql add trailing quotes to malformed statements 2020-01-02 14:10:23 -05:00
tiger_loader_2020.sql Prevent _ from matching any character. References #4959 for PostGIS 3.2.0. Mistake on last commit 2021-07-31 23:48:11 -04:00
tiger_loader_2021.sql Update to support TIGER 2021. References #5039 for PostGIS 3.3.0 2022-06-13 22:51:13 -04:00
tiger_loader_2022.sql Support for tiger 2022 files 2022-11-05 01:18:24 -04:00
upgrade_geocode.sql CREATE TABLE IF NOT EXISTS is now supported on all we support 2021-07-29 18:07:04 -04:00
upgrade_geocoder.bat Fix issue with loading tabblock 2019-09-28 02:52:11 +00:00
upgrade_geocoder.sh Standardize shebangs 2020-07-01 11:00:58 +02:00

Installing The Tiger Geocoder

This is a customized version of Steve Frost's tiger geocoder revisions.

This version includes a loader that is portable between Linux and
Windows but loads a full state of data at a time.  The loader helper tables and
functions are prefixed with loader and stored in the tiger schema.  If
you only want to load a county, revise the wget call that is generated
for the state to just download the statewide and specific counties or
just download them by hand.  The loader will only process files that
exist.

If you are on windows, you will need 7zip and wget.  7zip you can get
from http://www.7-zip.org/ and wget you can get from
http://gnuwin32.sourceforge.net/packages/wget.htm

Tiger Geocoder is now part of the PostGIS documentation
for further details about function use, refer to:
http://postgis.net/docs/manual-dev/Extras.html#Tiger_Geocoder

Refer to http://postgis.net/docs/manual-dev/postgis_installation.html#install_tiger_geocoder_extension 
for installing, upgrading, and loading data from extensions.

Note that installing by script approach is now deprecated, but covered in: 
http://postgis.net/docs/manual-dev/postgis_installation.html#install_tiger_geocoder

Loading data:

1. Create a folder called gisdata on root of server or your local pc
if you have a fast network connection to the server. This folder is
where the tiger files will be downloaded to.

2. Create a folder called temp in the gisdata folder.  This will be
the folder where we extract the downloaded tiger data.

3. Run the following commands at psql or pgAdmin III query window to
generate the script, replacing 'DC', 'RI' with list of states you want
and save contents to a .bat or sh file in YOUR CURRENT DIRECTORY. This
will generate CODE for each state and append it to the script.

(IF YOU ARE AT A PSQL PROMPT, FIRST RUN "\a", "\t", AND "\o
script.xxx".  THIS WILL MAKE YOUR OUTPUT UNALIGNED AND REDIRECT IT TO
script.xxx.  WITHOUT "\a" and "\t", THE SCRIPT WILL HAVE EXTRA
WHITESPACE AND POSSIBLY NON-SCRIPT CHARACTERS THAT CAUSE IT TO BREAK.)

-- UNIX /LINUX USERS --
-- Note even if you want just specific states you need to 
-- do this step since 2015 county, state tables are available only at national level
SELECT loader_generate_nation_script('sh');  

-- After the nation load, generate a bash script suitable for Unix command lines 
-- for your desired states. 

SELECT loader_generate_script(ARRAY['DC','RI'], 'sh');


ONCE YOU GENERATE THIS SCRIPT, EDIT IT TO ADD "set -e -u" AT THE TOP;
THIS SETTING WILL MAKE IT STOP ON ERROR OR UNITIALIZED VARIABLE AND
MAKE IT EASIER TO DEBUG ANY PROBLEMS.  
THEN RUN THE SCRIPT AT THE COMMAND LINE, REDIRECTING STANDARD OUTPUT AND 
STANDARD ERROR TO USEFUL FILES.  YOU MAY WANT TO RUN "tail -f " TO SEE THE 
STANDARD ERROR AS IT GETS WRITTEN.  FOR EXAMPLE: 

$ sh foo.sh 1>out 2>err; tail -f err

-- WINDOWS USERS --
--To generate a WINDOWS DOS script
-- this will generate the script to download the national layers
-- Note even if you want just specific states you need to 
-- do this step since 2011 county, state tables are available only at national level
SELECT loader_generate_nation_script('windows');  

-- this you do after the nation load and for states you want
SELECT loader_generate_script(ARRAY['DC','RI'], 'windows');

If your script disappears without loading anything, 
most likely one of your path settings is wrong. 
To troubleshoot run the batch script by 
first opening up a commandline and executing the file. 

That will keep the window open for you to see the error.

-- Next run the script to install any missing indexes --
SELECT install_missing_indexes();

Alternatively if you want to see what indexes will be created before
you create them run the below and manually run the steps generated:
SELECT missing_indexes_generate_script();


9. Copy and paste the generated script into a .bat or .sh file and put
in gisdata folder you created and then run it, OR IF YOU REDIRECTED
THE OUTPUT TO A FILE WITH "\o" MOVE THAT FILE TO GISDATA.

10. Test out the geocoder run these queries

-- To get the best rated answer --
-- this is generally faster
SELECT g.rating, 
	ST_X(geomout) As lon, 
	ST_Y(geomout) As lat, (addy).* 
FROM geocode('1731 New Hampshire Avenue Northwest, Washington, DC 20010', 1) As g;

--To get multiple answers if there is more than 1
SELECT g.rating, 
	ST_X(geomout) As lon, 
	ST_Y(geomout) As lat, (addy).* 
FROM geocode('1731 New Hampshire Avenue Northwest, Washington, DC 20010') As g;