- PostgreSQL >= 11
- PostGIS >= 2.5
- GDAL >= 2.1
- curl
- unzip
- iconv
Copy
.env.exampleto.env.$ cd /path/to/pgGeocoder $ cp .env.example .envOpen
.envfile with some text editor and adjust database settings and the years of the dataset to import.DBROLE=postgres DBPASS=postgres DBNAME=addresses DBHOST=localhost DBPORT=5432 YEAR_ISJ=2023 YEAR_KSJ=2023 YEAR_ESTAT=2020Note: To download and install address data from multiple years to have a historical data set, the
YEAR_ISJparameter can be set as follows:YEAR_ISJ="2023,2017,2013"Be aware though that this will require substantial disk space resources.
Create address database (with same as
.envvalues).
(If the database exists, drop it at first.)$ dropdb -U postgres addresses $ createdb -U postgres addresses
Run install and download/import scripts.
$ bash scripts/install.sh $ bash scripts/import_data.sh
Run maintenance script.
$ bash scripts/maintenance.sh
If keeping original data source tables is preferable, add
1as the argument.$ bash scripts/maintenance.sh 1
Note: The maintainance script will take around 45 mins to complete depending on the specs of the computer.
About tables structure, check the following files.
- createTables.sql: Define each tables and columns, but without indexes.
- maintTables.sql: Define indexes.
About functions, check the following files.
- pgGeocoder.sql: Define
geocoderfunction. - pgReverseGeocoder.sql: Define
reverse_geocoderfunction.
$ psql -U postgres addresses- Geocode on address:
select*from geocoder('京都府京都市中京区河原町通四条上る米屋町380-1ツジクラビル1階');
code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+------------+-----------+---------------------------+-----------+-------------+-------+--------+---- 2 | 135.769661 | 35.004476 | 京都府京都市中京区米屋町380番 | 京都府 | 京都市中京区 | 米屋町 | 380 | (1 row)select*from geocoder('神奈川県横浜市西区みなとみらい3−6−3');
code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+------------+-----------+---------------------------------+-----------+-------------+----------------+--------+---- 1 | 139.632805 | 35.458282 | 神奈川県横浜市西区みなとみらい三丁目6番 | 神奈川県 | 横浜市西区 | みなとみらい三丁目 | 6 | 3 (1 row) - Reverse geocode on address:
select*from reverse_geocoder(141.342094, 43.050264);
code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+-------------------+-------------------+---------------------------------------+-----------+--------------+------------------+--------+---- 1 | 141.3421173095703 | 43.05035400390625 | 北海道札幌市中央区南七条西十一丁目4-5 | 北海道 | 札幌市中央区 | 南七条西十一丁目 | 4 | 5 (1 row) - Reverse geocode a coordinate and specify search distance in meters (lon, lat, meters)
select*from reverse_geocoder(141.342094, 43.050264, 50);
code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+-------------------+-------------------+---------------------------------------+-----------+--------------+------------------+--------+---- 1 | 141.3421173095703 | 43.05035400390625 | 北海道札幌市中央区南七条西十一丁目4-5 | 北海道 | 札幌市中央区 | 南七条西十一丁目 | 4 | 5 (1 row)
- 位置参照情報 (ISJ)
- Website: http://nlftp.mlit.go.jp/isj/index.html
- Format: CSV (Zipped)
- Geometry Type: Point
- Remarks:
- Point based address data for "Gaiku Level" (街区レベル) and "Oaza Level" (大字・町丁目レベル).
- e-Stat 国勢調査町丁・字等別境界データ
- Website: https://www.e-stat.go.jp/gis/statmap-search?page=1&type=2&aggregateUnitForBoundary=A&toukeiCode=00200521
- Format: ESRI Shapefile (or GML)
- Geometry Type: Polygon
- Remarks:
- Almost "Oaza Level" (大字・町丁目レベル) admin boundary data, but some boundaries are merged for Japanese census survey units.
- Each prefectures' boundaries are not adjusted (snapped), so some overlaps and gaps exist.
- 国土数値情報 (KSJ)
- Website: https://nlftp.mlit.go.jp/ksj/index.html
- Format: ESRI Shapefile (or GML)
- 行政区域データ:
- Website: https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-N03-2023.html
- Geometry Type: Polygon
- Remarks:
- "City Level" (市区町村レベル) admin boundary data.
- 市区町村役場データ:
- Website: https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P34.html
- Geometry Type: Point
- Remarks:
- "City Office" (市区町村役場) point data.
- 国・都道府県の機関データ:
- Website: https://nlftp.mlit.go.jp/ksj/gml/datalist/KsjTmplt-P28-2022.html
- Geometry Type: Point
- Remarks:
- Geovernment data which includes "Prefectural Office" (都道府県庁) point data.
- デジタル庁 アドレス・ベース・レジストリ (ABR)
- Website: https://www.digital.go.jp/policies/base_registry_address
- Format: CSV (Zipped)
- Geometry Type: Point
- Remarks:
- Pinpoint Data for selected areas.
For
Bulk Geocoding, wherein addresses located in a field of a table are geocoded, please see this WIKI Entry.To create
TRIGGERSthat will geocode addresses automatically on anINSERTorUPDATEoperation, please see this WIKI Entry.To do
Spatial AnalyticsusingpgGeocoderwith GeoFuse, please see this WIKI EntryTo view the FOSS4G Presentation for pgGeocoder, please see this WIKI Entry