PostGIS 3.5 Tiger 地理编码速查表

此版本新增1 此版本增强2  
地址标准化器
stdaddr    一种由地址元素组成的复合类型。这是 standardize_address 函数的返回类型。
规则表    规则表包含一组规则,用于将地址输入序列标记映射到标准化的输出序列。规则定义为一组输入标记,后跟 -1 (终止符),后跟一组输出标记,后跟 -1,后跟表示规则类型的数字,后跟规则的排名。
词法表    词法表用于对字母数字输入进行分类,并将该输入与 (a) 输入标记 (参见) 和 (b) 标准化表示相关联。
地名词典表    地名词典表用于标准化地名,并将该输入与 (a) 输入标记 (参见) 和 (b) 标准化表示相关联。
debug_standardize_address (lextab, gaztab, rultab, micro, macro=NULL)    返回一个 json 格式的文本,列出解析标记和标准化结果
parse_address (address)    接收一行地址并将其分解为各个部分
standardize_address    利用词法表、地名词典表和规则表返回输入地址的 stdaddr 形式。
  1. lextab, gaztab, rultab, address
  2. lextab, gaztab, rultab, micro, macro

Tiger 地理编码器
Drop_Indexes_Generate_Script (param_schema=tiger_data)    生成一个脚本,该脚本会删除 tiger 模式和用户指定的模式上所有非主键和非唯一索引。如果未指定模式,则默认模式为 tiger_data。
Drop_Nation_Tables_Generate_Script (param_schema=tiger_data)    生成一个脚本,该脚本会删除指定模式中所有以 county_all、state_all 或州代码开头后跟 county 或 state 的表。
Drop_State_Tables_Generate_Script (param_state, param_schema=tiger_data)    生成一个脚本,该脚本会删除指定模式中所有以州缩写为前缀的表。如果未指定模式,则默认模式为 tiger_data。
Geocode    接收一个地址作为字符串(或其他标准化地址),并输出一组可能的位置,其中包括 NAD 83 经纬度中的点几何、每个位置的标准化地址以及评分。评分越低,匹配的可能性越高。结果按评分最低的优先排序。可以选择传入最大结果数(默认为 10)和 restrict_region(默认为 NULL)
  1. address, max_results=10, restrict_region=NULL,
  2. in_addy, max_results=10, restrict_region=NULL,
Geocode_Intersection ( roadway1, roadway2, in_state, in_city, in_zip, max_results=10, )    接收两条相交的街道以及州、城市、邮政编码,并输出第一条交叉街道上可能的位置集合,其中包含 NAD 83 经纬度中的点位置的 geomout、每个位置的 normalized_address (addy) 以及评分。评分越低,匹配的可能性越高。结果按评分最低的优先排序。可以选择传入最大结果数,默认为 10。使用 Tiger 数据(edges、faces、addr)、PostgreSQL 模糊字符串匹配(soundex、levenshtein)。
Get_Geocode_Setting ( setting_name)    返回存储在 tiger.geocode_settings 表中的特定设置的值。
Get_Tract ( loc_geom, output_field=name)    返回几何所在位置的普查区或来自普查区表的字段。默认返回普查区的简称。
Install_Missing_Indexes ()    查找所有在地理编码器连接和筛选条件中使用但缺少索引的表,并在这些列上添加索引。
Loader_Generate_Census_Script (param_states, os)    为指定的平台和指定的州生成 shell 脚本,该脚本将下载 Tiger 普查州普查区、bg 和 tabblocks 数据表,并将其暂存并加载到 tiger_data 模式中。每个州脚本都作为单独的记录返回。
Loader_Generate_Script (param_states, os)    为指定的平台和指定的州生成 shell 脚本,该脚本将下载 Tiger 数据,并将其暂存并加载到 tiger_data 模式中。每个州脚本都作为单独的记录返回。最新版本支持 Tiger 2010 结构更改,并且还加载普查区、街区组和街区表。
Loader_Generate_Nation_Script (os)    为指定平台生成一个 shell 脚本,该脚本将加载县和州查找表。
Missing_Indexes_Generate_Script ()    查找所有在地理编码器连接中使用但缺少索引的表,并输出 SQL DDL 以定义这些表的索引。
Normalize_Address (in_address)    给定一个文本街道地址,返回一个 norm_addy 复合类型,该类型具有标准化的道路后缀、前缀和类型,街道、街道名称等分解为单独的字段。此函数仅使用与 tiger_geocoder 一起打包的查找数据即可工作(不需要 tiger 普查数据)。
Pagc_Normalize_Address (in_address)    给定一个文本街道地址,返回一个 norm_addy 复合类型,该类型具有标准化的道路后缀、前缀和类型,街道、街道名称等分解为单独的字段。此函数仅使用与 tiger_geocoder 一起打包的查找数据即可工作(不需要 tiger 普查数据)。需要 address_standardizer 扩展。
Pprint_Addy (in_addy)    给定一个 norm_addy 复合类型对象,返回其美观的打印表示形式。通常与 normalize_address 结合使用。
Reverse_Geocode (pt, include_strnum_range=false, )    接收已知空间参考系统中的几何点,并返回一个记录,其中包含理论上可能的地址数组和交叉街道数组。如果 include_strnum_range = true,则在交叉街道中包含街道范围。
Topology_Load_Tiger (topo_name, region_type, region_id)    将定义的 tiger 数据区域加载到 PostGIS 拓扑中,并将 tiger 数据转换为拓扑的空间参考并捕捉到拓扑的精度容差。
Set_Geocode_Setting ( setting_name, setting_value)    设置影响地理编码器函数行为的设置。

地址标准化器示例
Tiger 地理编码器示例
Drop_Indexes_Generate_Script
SELECT drop_indexes_generate_script() As actionsql;
actionsql
---------------------------------------------------------
DROP INDEX tiger.idx_tiger_countysub_lookup_lower_name;
DROP INDEX tiger.idx_tiger_edges_countyfp;
DROP INDEX tiger.idx_tiger_faces_countyfp;
DROP INDEX tiger.tiger_place_the_geom_gist;
DROP INDEX tiger.tiger_edges_the_geom_gist;
DROP INDEX tiger.tiger_state_the_geom_gist;
DROP INDEX tiger.idx_tiger_addr_least_address;
DROP INDEX tiger.idx_tiger_addr_tlid;
DROP INDEX tiger.idx_tiger_addr_zip;
DROP INDEX tiger.idx_tiger_county_countyfp;
DROP INDEX tiger.idx_tiger_county_lookup_lower_name;
DROP INDEX tiger.idx_tiger_county_lookup_snd_name;
DROP INDEX tiger.idx_tiger_county_lower_name;
DROP INDEX tiger.idx_tiger_county_snd_name;
DROP INDEX tiger.idx_tiger_county_the_geom_gist;
DROP INDEX tiger.idx_tiger_countysub_lookup_snd_name;
DROP INDEX tiger.idx_tiger_cousub_countyfp;
DROP INDEX tiger.idx_tiger_cousub_cousubfp;
DROP INDEX tiger.idx_tiger_cousub_lower_name;
DROP INDEX tiger.idx_tiger_cousub_snd_name;
DROP INDEX tiger.idx_tiger_cousub_the_geom_gist;
DROP INDEX tiger_data.idx_tiger_data_ma_addr_least_address;
DROP INDEX tiger_data.idx_tiger_data_ma_addr_tlid;
DROP INDEX tiger_data.idx_tiger_data_ma_addr_zip;
DROP INDEX tiger_data.idx_tiger_data_ma_county_countyfp;
DROP INDEX tiger_data.idx_tiger_data_ma_county_lookup_lower_name;
DROP INDEX tiger_data.idx_tiger_data_ma_county_lookup_snd_name;
DROP INDEX tiger_data.idx_tiger_data_ma_county_lower_name;
DROP INDEX tiger_data.idx_tiger_data_ma_county_snd_name;
:
:
Drop_Nation_Tables_Generate_Script
SELECT drop_nation_tables_generate_script();
DROP TABLE tiger_data.county_all;
DROP TABLE tiger_data.county_all_lookup;
DROP TABLE tiger_data.state_all;
DROP TABLE tiger_data.ma_county;
DROP TABLE tiger_data.ma_state;
Drop_State_Tables_Generate_Script
SELECT drop_state_tables_generate_script('PA');
DROP TABLE tiger_data.pa_addr;
DROP TABLE tiger_data.pa_county;
DROP TABLE tiger_data.pa_county_lookup;
DROP TABLE tiger_data.pa_cousub;
DROP TABLE tiger_data.pa_edges;
DROP TABLE tiger_data.pa_faces;
DROP TABLE tiger_data.pa_featnames;
DROP TABLE tiger_data.pa_place;
DROP TABLE tiger_data.pa_state;
DROP TABLE tiger_data.pa_zip_lookup_base;
DROP TABLE tiger_data.pa_zip_state;
DROP TABLE tiger_data.pa_zip_state_loc;
        
Geocode
SELECT g.rating, ST_X(g.geomout) As lon, ST_Y(g.geomout) As lat,
    (addy).address As stno, (addy).streetname As street,
    (addy).streettypeabbrev As styp, (addy).location As city, (addy).stateabbrev As st,(addy).zip
    FROM geocode('75 State Street, Boston MA 02109', 1) As g;
 rating |        lon        |      lat       | stno | street | styp |  city  | st |  zip
--------+-------------------+----------------+------+--------+------+--------+----+-------
      0 | -71.0557505845646 | 42.35897920691 |   75 | State  | St   | Boston | MA | 02109
Geocode_Intersection
SELECT pprint_addy(addy), st_astext(geomout),rating
            FROM geocode_intersection( 'Haverford St','Germania St', 'MA', 'Boston', '02130',1);
           pprint_addy            |         st_astext          | rating
----------------------------------+----------------------------+--------
98 Haverford St, Boston, MA 02130 | POINT(-71.101375 42.31376) |      0
Get_Geocode_Setting
SELECT get_geocode_setting('debug_geocode_address) As result;
result
---------
false
        
Get_Tract
SELECT get_tract(ST_Point(-71.101375, 42.31376) ) As tract_name;
tract_name
---------
1203.01
        
Install_Missing_Indexes
SELECT install_missing_indexes();
         install_missing_indexes
-------------------------
 t
        
Loader_Generate_Census_Script
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');"
: 
Loader_Generate_Script
psql -U postgres -h localhost -d gistest -A -t \
 -c "SELECT Loader_Generate_Script(ARRAY['MA'], 'gistest')" > /gisdata/data_load.sh;
Loader_Generate_Nation_Script
SELECT loader_generate_nation_script('windows'); 
Missing_Indexes_Generate_Script
SELECT missing_indexes_generate_script();
-- output: This was run on a database that was created before many corrections were made to the loading script ---
CREATE INDEX idx_tiger_county_countyfp ON tiger.county USING btree(countyfp);
CREATE INDEX idx_tiger_cousub_countyfp ON tiger.cousub USING btree(countyfp);
CREATE INDEX idx_tiger_edges_tfidr ON tiger.edges USING btree(tfidr);
CREATE INDEX idx_tiger_edges_tfidl ON tiger.edges USING btree(tfidl);
CREATE INDEX idx_tiger_zip_lookup_all_zip ON tiger.zip_lookup_all USING btree(zip);
CREATE INDEX idx_tiger_data_ma_county_countyfp ON tiger_data.ma_county USING btree(countyfp);
CREATE INDEX idx_tiger_data_ma_cousub_countyfp ON tiger_data.ma_cousub USING btree(countyfp);
CREATE INDEX idx_tiger_data_ma_edges_countyfp ON tiger_data.ma_edges USING btree(countyfp);
CREATE INDEX idx_tiger_data_ma_faces_countyfp ON tiger_data.ma_faces USING btree(countyfp);
        
Normalize_Address
SELECT address As orig, (g.na).streetname, (g.na).streettypeabbrev
 FROM (SELECT address, normalize_address(address) As na
        FROM addresses_to_geocode) As g;

                        orig                         |  streetname   | streettypeabbrev
-----------------------------------------------------+---------------+------------------
 28 Capen Street, Medford, MA                        | Capen         | St
 124 Mount Auburn St, Cambridge, Massachusetts 02138 | Mount Auburn  | St
 950 Main Street, Worcester, MA 01610                | Main          | St
 529 Main Street, Boston MA, 02129                   | Main          | St
 77 Massachusetts Avenue, Cambridge, MA 02139        | Massachusetts | Ave
 25 Wizard of Oz, Walaford, KS 99912323              | Wizard of Oz  |
        
Pagc_Normalize_Address
SELECT addy.*
FROM pagc_normalize_address('9000 E ROO ST STE 999, Springfield, CO') AS addy;


 address | predirabbrev | streetname | streettypeabbrev | postdirabbrev | internal  |  location   | stateabbrev | zip | parsed
---------+--------------+------------+------------------+---------------+-----------+-------------+-------------+-----+--------
    9000 | E            | ROO        | ST               |               | SUITE 999 | SPRINGFIELD | CO          |     | t
Pprint_Addy
SELECT pprint_addy(normalize_address('202 East Fremont Street, Las Vegas, Nevada 89101')) As pretty_address;
            pretty_address
---------------------------------------
 202 E Fremont St, Las Vegas, NV 89101
        
Reverse_Geocode
SELECT pprint_addy(r.addy[1]) As st1, pprint_addy(r.addy[2]) As st2, pprint_addy(r.addy[3]) As st3,
            array_to_string(r.street, ',') As cross_streets
        FROM reverse_geocode(ST_GeomFromText('POINT(-71.093902 42.359446)',4269),true) As r;

 result
 ------
      st1                                  | st2 | st3 |               cross_streets
-------------------------------------------+-----+-----+----------------------------------------------
 67 Massachusetts Ave, Cambridge, MA 02139 |     |     | 67 - 127 Massachusetts Ave,32 - 88 Vassar St
Topology_Load_Tiger
SELECT topology.CreateTopology('topo_boston', 2249, 0.25);
createtopology
--------------
   15
-- 60,902 ms ~ 1 minute on windows 7 desktop running 9.1 (with 5 states tiger data loaded)
SELECT tiger.topology_load_tiger('topo_boston', 'place', '2507000');
-- topology_loader_tiger --
29722 edges holding in temporary. 11108 faces added. 1875 edges of faces added.  20576 nodes added.
19962 nodes contained in a face.  0 edge start end corrected.  31597 edges added.

-- 41 ms --
SELECT topology.TopologySummary('topo_boston');
 -- topologysummary--
Topology topo_boston (15), SRID 2249, precision 0.25
20576 nodes, 31597 edges, 11109 faces, 0 topogeoms in 0 layers

-- 28,797 ms to validate yeh returned no errors --
SELECT * FROM
    topology.ValidateTopology('topo_boston');

       error       |   id1    |    id2
-------------------+----------+-----------
      
Set_Geocode_Setting
SELECT set_geocode_setting('debug_geocode_address', 'true') As result;
result
---------
true