Skip to content

gtt-project/pgGeocoder

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgGeocoder - Japanese Geocoder on PostgreSQL

Requirements

  • PostgreSQL >= 11
  • PostGIS >= 2.5
  • GDAL >= 2.1
  • curl
  • unzip
  • iconv

Setup

  1. Copy .env.example to .env.
    $ cd /path/to/pgGeocoder
    $ cp .env.example .env
  2. Open .env file with some text editor and adjust database settings.
    DBROLE=postgres
    DBPASS=postgres
    DBNAME=addresses
    DBHOST=localhost
    DBPORT=5432
    
  3. Create address database (with same as .env values).
    (If the database exists, drop it at first.)
    # dropdb -U postgres addresses
    $ createdb -U postgres addresses
  4. Run install and download/import scripts.
    $ bash scripts/install.sh
    $ bash scripts/download_isj.sh 2020
    $ bash scripts/import_isj.sh 2020
    $ bash scripts/download_estat.sh 2015
    $ bash scripts/import_estat.sh 2015
    $ bash scripts/download_ksj.sh 2021
    $ bash scripts/import_ksj.sh 2021
    $ bash scripts/import_places.sh
  5. Run maintenance script.
    $ bash scripts/maintenance.sh
    If keeping original data source tables is preferable, add 1 as the argument.
    $ bash scripts/maintenance.sh 1

The above steps take about 45 mins on MacBook Pro (2.6 GHz 16GB RAM) environment.

Tables/Functions

About tables structure, check the following files.

About functions, check the following files.

Examples

$ 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 
    ------+------------+-----------+---------------------------------+-----------+-------------+----------------+--------+----
        2 | 139.632805 | 35.458282 | 神奈川県横浜市西区みなとみらい三丁目6番 | 神奈川県   | 横浜市西区    | みなとみらい三丁目 | 6      | 
    (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.341681 | 43.050529 | 北海道札幌市中央区南七条西十一丁目3 | 北海道     | 札幌市中央区  | 南七条西十一丁目 | 3      | 
    (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.341681 | 43.050529 | 北海道札幌市中央区南七条西十一丁目3 | 北海道     | 札幌市中央区  | 南七条西十一丁目 | 3      | 
    (1 row)
    

Data Sources

  1. 位置参照情報 (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" (大字・町丁目レベル).
  2. e-Stat 国勢調査町丁・字等別境界データ
  3. 国土数値情報 (KSJ)

About

Japanese Gecoder within PostgreSQL

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PLpgSQL 51.6%
  • Shell 42.1%
  • HTML 5.5%
  • TSQL 0.8%