### Install pgTAP from source Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Install pgTAP by cloning the repository and building it with make. Requires git and make. ```bash git clone git@github.com:theory/pgtap.git cd pgtap make make install ``` -------------------------------- ### Example .env Configuration Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Example .env file contents showing database connection settings and dataset years. Adjust these values to match your environment. ```bash DBROLE=postgres DBPASS=postgres DBNAME=addresses DBHOST=localhost DBPORT=5432 YEAR_ISJ=2023 YEAR_KSJ=2023 YEAR_ESTAT=2020 ``` -------------------------------- ### Run Install and Import Scripts Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Run the installation script and then the data import script to set up the geocoder and load address data. ```bash $ bash scripts/install.sh $ bash scripts/import_data.sh ``` -------------------------------- ### Install pg_prove on Linux Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Install pg_prove on Linux using CPAN. The environment is not yet verified. ```bash cpan TAP::Parser::SourceHandler::pgTAP ``` -------------------------------- ### Install benchmark data with psql Source: https://github.com/mbasa/pggeocoder/blob/master/benchmark/README.md Run the benchmark SQL script to create and populate the pgg_benchmark table, add a gc column of type geores, and geocode all addresses. Requires a database with pg_geocoder fully installed. ```shell psql -f pgg_benchmark.sql addresses2020 ``` -------------------------------- ### Copy .env.example to .env Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Navigate to the pgGeocoder directory and copy the example environment file to create the .env file. ```bash $ cd /path/to/pgGeocoder $ cp .env.example .env ``` -------------------------------- ### Install pg_prove on macOS Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Install pg_prove on macOS using Homebrew and CPAN. The last line is a placeholder for creating a symlink. ```bash brew install perl cpan TAP::Parser::SourceHandler::pgTAP ln -s $(find `brew --prefix` -name pg_prove) symlink it into $(brew --prefix)/bin ``` -------------------------------- ### Connect to the addresses database with psql Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Connects to the addresses database as the postgres user to run the geocoding examples. ```bash $ psql -U postgres addresses ``` -------------------------------- ### URL with viewparams for geocoder Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service Example URL showing how to pass the address parameter via viewparams to the GeoServer service. ```url http://localhost:8080/geoserver/?....&viewparams=address:京都市上京区竹屋町通り松屋町西入ル藁屋町535番地 ``` -------------------------------- ### Reverse Geocoder Request URLs Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service Example URLs for using the Reverse Geocoder. The first shows the general viewparams format, and the second is a complete WFS GetFeature request with the reverse_geocoder type name. ```url http://localhost:8080/geoserver/?....&viewparams=lat:35.016256;lon:135.748032 ``` ```url http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typenames=geocoder:reverse_geocoder&viewparams=lat:35.016256;lon:135.748032 ``` -------------------------------- ### Multiple Year YEAR_ISJ Setting Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Set YEAR_ISJ to a comma-separated list of years to download and install address data for multiple years, creating a historical dataset. This requires substantial disk space. ```bash YEAR_ISJ="2023,2017,2013" ``` -------------------------------- ### Create dblink extension Source: https://github.com/mbasa/pggeocoder/wiki/Geocoding-from-Different-Database Installs the dblink extension in the current database, which is required to call functions in another database. This package is normally included in recent PostgreSQL versions. ```sql statistics=# create extension dblink; ``` -------------------------------- ### Load test data from fixtures Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Set up test data by copying the environment file and running the fixture loading script. The default test database name is addresses_test, configurable in tests/.env. ```bash cp tests/.env.test tests/.env bash tests/create_test_db_from_fixtures.sh ``` -------------------------------- ### Navigate to test directory Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Change to the test directory before running tests. ```bash cd tests ``` -------------------------------- ### Create Address Database Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Drop the existing addresses database if it exists, then create a new one with the same name. Use the same values as in the .env file. ```bash $ dropdb -U postgres addresses $ createdb -U postgres addresses ``` -------------------------------- ### Update fixtures from production tables Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Dump basic columns from production tables address_t, address_s, and address_o into fixtures/address_*.csv.gz files. ```bash bash tests/dump_prod_tables_to_fixtures.sh ``` -------------------------------- ### Run Maintenance Script Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Run the maintenance script to create indexes and perform other maintenance tasks. This can take around 45 minutes depending on computer specs. ```bash $ bash scripts/maintenance.sh ``` -------------------------------- ### Create sample table trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Creates a table with an id serial, address text, and gc column of type GEORES to store geocoding results. ```sql CREATE TABLE trigtable (id SERIAL,address TEXT,gc GEORES); ``` -------------------------------- ### Run pg_prove tests Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Run pgTAP tests using pg_prove. Recommended for detecting errors. ```bash pg_prove -U postgres -d addresses_test addresses.test.sql ``` -------------------------------- ### WMS sample URL with geocoder request Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service Sample WMS GetMap request URL that includes the viewparams parameter to geocode an address and return a map. ```url http://localhost:8080/geoserver/geocoder/wms?service=WMS&version=1.1.0&request=GetMap&layers=geocoder:pale,geocoder:geocoder&bbox=1.4437799E7%2C3596807.25%2C1.5857083E7%2C5361010.0&width=900&height=500&srs=EPSG%3A3857&styles=&format=application/openlayers&viewparams=address:京都市上京区竹屋町通り松屋町西入ル藁屋町535番地 ``` -------------------------------- ### Benchmark geocoding rate with timing Source: https://github.com/mbasa/pggeocoder/blob/master/benchmark/README.md Enable psql timing and geocode the entire table with an UPDATE statement. The output shows the number of updated rows and the elapsed time; the time result is from a MacBook Pro M1 with 16GB memory and will vary by machine. ```sql \timing on update pgg_benchmark set gc = geocoder( address ); UPDATE 124729 Time: 163124.479 ms (02:43.124) ``` -------------------------------- ### WFS sample URL with geocoder request Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service Sample WFS GetFeature request URL that includes the viewparams parameter to geocode an address and return attributes. ```url http://localhost:8080/geoserver/wfs?service=WFS&version=1.1.0&request=GetFeature&typenames=geocoder:geocoder&viewparams=address:京都市上京区竹屋町通り松屋町西入ル藁屋町535番地 ``` -------------------------------- ### Run pgTAP tests directly Source: https://github.com/mbasa/pggeocoder/blob/master/tests/README.md Run pgTAP tests directly with psql against the addresses_test database. ```bash psql -U postgres -d addresses_test -f addresses.test.sql ``` -------------------------------- ### Table definition output for trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Shows the resulting table structure including columns, types, defaults, and the trigger definition. ```text Table "public.trigtable" Column | Type | Collation | Nullable | Default ---------+---------+-----------+----------+--------------------------------------- id | integer | | not null | nextval('trigtable_id_seq'::regclass) address | text | | | gc | geores | | | Triggers: trigtable_trigger1 BEFORE INSERT OR UPDATE ON trigtable FOR EACH ROW EXECUTE FUNCTION geocder_trigger_func() ``` -------------------------------- ### Run Maintenance Script with Keep Tables Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Run the maintenance script with argument 1 to keep the original data source tables. This is optional if you prefer to retain them. ```bash $ bash scripts/maintenance.sh 1 ``` -------------------------------- ### Drill Down to Ooaza with SQL WHERE and GROUP BY Source: https://github.com/mbasa/pggeocoder/wiki/Spatial-Analytics Drills down from Shikuchoson to Ooaza level by filtering to a specific Shikuchoson and grouping by Ooaza name. Requires an ooaza_name column in the passed data. ```sql select (gc).todofuken||(gc).shikuchoson||(gc).ooaza as ooaza_name, sum(last_sales)::int as 先月売上, sum(this_sales)::int as 今月売上 from tokyo_demo where (gc).shikuchoson = '杉並区' ``` -------------------------------- ### Select addresses from taddr Source: https://github.com/mbasa/pggeocoder/wiki/Geocoding-from-Different-Database Shows the addresses in the taddr table that will be geocoded. The output lists 20 sample addresses in Japanese. ```sql select address from taddr; ``` ```text address -------------------- 函館市栄町7-3 函館市大町4-4 室蘭市幸町7番6号 函館市時任町8-5 函館市柳町9番5号 江東区冬木5-2 板橋区大門7-5 江東区石島4-4 江東区千田6-1 板橋区仲町1-4 池田市栄町3番3号 交野市松塚1番1号 守口市淀江町3-5 守口市祝町9-18 池田市栄町7-13 名護市城1-1-3 那覇市辻2-4-1 那覇市東町26-1 那覇市西3-4-1 那覇市山下町3-1 (20 rows) ``` -------------------------------- ### Aggregate by Shikuchoson with SQL GROUP BY Source: https://github.com/mbasa/pggeocoder/wiki/Spatial-Analytics Aggregates point data by Shikuchoson name using SQL GROUP BY and SUM() to prepare a table for GeoFuse thematics. Requires a shikuchoson_name column in the passed data. ```sql select (gc).todofuken||(gc).shikuchoson as shikuchoson_name, sum(last_sales)::int as 先月売上, sum(this_sales)::int as 今月売上 from tokyo_demo group by (gc).todofuken,(gc).shikuchoson; ``` -------------------------------- ### Geocode two addresses and find shortest path with pg_dijkstra_go Source: https://github.com/mbasa/pggeocoder/wiki/Finding-a-Route-between-2-Addresses Geocodes two Kyoto addresses with the geocoder() function, converts each result to a PostGIS point with ST_SETSRID(ST_POINT(...),4326), finds the nearest road-network node in japan_v using the <-> operator, and passes the source and target nodes plus the graph (id, source, target, cost) to pg_dijkstra_go to compute the shortest path. The same statement can be wrapped in a TRIGGER to run on every INSERT or UPDATE. ```sql with -- -- Geocoding address and getting the source node -- source as (select source::integer as pt from japan_v order by geom <-> (select ST_SETSRID(ST_POINT(a.x,a.y),4326) from geocoder('京都市上京区竹屋町通り松屋町西入ル藁屋町535番地') a) limit 1), -- -- Geocoding address and getting the target node -- target as (select source::integer as pt from japan_v order by geom <-> (select ST_SETSRID(ST_POINT(a.x,a.y),4326) from geocoder('向日市寺戸町七ノ坪30番地ジオ阪急洛西口ノースレジデンス1階') a) limit 1) -- -- Finding the route between the two addresses -- select pg_dijkstra_go((select json_agg(graph)::text from (select id,source,target,cost from japan_v) graph), (select pt from source), (select pt from target) ); ``` -------------------------------- ### Query Pinpoint and Banchi matches for Tokyo Source: https://github.com/mbasa/pggeocoder/blob/master/benchmark/README.md Query the benchmark table to list Pinpoint and Banchi level matches (code <= 2) for Tokyo addresses, showing the geocoder result code, address, and coordinates. ```sql select (gc).code,address,(gc).x,(gc).y from pgg_benchmark where (gc).code <= 2 and (gc).todofuken = '東京都'; ``` -------------------------------- ### Display geocoder data from trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Selects the geocoding components (code, todofuken, shikuchoson, ooaza, chiban, x, y) from the gc column. ```sql select (gc).code,(gc).todofuken,(gc).shikuchoson, (gc).ooaza,(gc).chiban,(gc).x,(gc).y from trigtable; ``` -------------------------------- ### Display geocoding results Source: https://github.com/mbasa/pggeocoder/wiki/Bulk-Geocoding Selects the address, geocoder result code, and x,y coordinates from the table. ```sql SELECT address,(gc).code,(gc).x,(gc).y FROM table_name; ``` -------------------------------- ### Geocode addresses with geocoder function Source: https://github.com/mbasa/pggeocoder/wiki/Spatial-Analytics Populates the gc column by calling the pgGeocoder geocoder function on the address column. The demo table with 40,578 records took 61 seconds on a MacBook Pro M1. ```sql UPDATE tokyo_demo SET gc = geocoder( address ); ``` -------------------------------- ### Extract lon/lat for GeoFuse Source: https://github.com/mbasa/pggeocoder/wiki/Spatial-Analytics Selects address, sales metrics, and longitude/latitude from the geocoded gc column for use with GeoFuse. The output can be copied with headers in pgAdmin and pasted into GeoFuse. ```sql select address, last_sales::int as 先月売上, this_sales::int as 今月売上, (gc).x as lon, (gc).y as lat from tokyo_demo; ``` -------------------------------- ### Output of updated addresses Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Shows the result of the select query after the update, with row 5 having the new address. ```text id | address ----+---------------------------------------------------------------- 1 | 京都府京都市上京区御前通今出川上ル馬喰町885 2 | 京都府京都市中京区二条通富小路東入晴明町673-2 3 | 京都府京都市中京区河原町蛸薬師東側塩屋町324古城ビル地下1F 4 | 京都府京都市中京区御池通寺町東入下本能寺前町492番地1他 5 | 北海道札幌市白石区東札幌五条5-4-30-2 (5 rows) ``` -------------------------------- ### Output of inserted addresses Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Shows the result of the select query with the five inserted addresses. ```text id | address ----+---------------------------------------------------------------- 1 | 京都府京都市上京区御前通今出川上ル馬喰町885 2 | 京都府京都市中京区二条通富小路東入晴明町673-2 3 | 京都府京都市中京区河原町蛸薬師東側塩屋町324古城ビル地下1F 4 | 京都府京都市中京区御池通寺町東入下本能寺前町492番地1他 5 | 京都府京都市上京区今出川通六軒町西入西上善寺町207-6 (5 rows) ``` -------------------------------- ### Geocode an address with geocoder() Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Geocodes a Japanese address using the geocoder function. The output shows the result with code 2, coordinates, normalized address, and administrative divisions. ```sql select * from geocoder('京都府京都市中京区河原町通四条上る米屋町380-1ツジクラビル1階'); ``` ```text code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+------------+-----------+---------------------------+-----------+-------------+-------+--------+---- 2 | 135.769661 | 35.004476 | 京都府京都市中京区米屋町380番 | 京都府 | 京都市中京区 | 米屋町 | 380 | (1 row) ``` -------------------------------- ### Output of geocoder data after insert Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Shows the geocoding results for the inserted addresses, including coordinates. ```text code | todofuken | shikuchoson | ooaza | chiban | x | y ------+-----------+--------------+--------------+--------+------------+----------- 2 | 京都府 | 京都市上京区 | 馬喰町 | 885 | 135.736477 | 35.030054 2 | 京都府 | 京都市中京区 | 晴明町 | 673 | 135.765329 | 35.013509 2 | 京都府 | 京都市中京区 | 塩屋町 | 324 | 135.769512 | 35.005731 2 | 京都府 | 京都市中京区 | 下本能寺前町 | 492 | 135.767985 | 35.010143 2 | 京都府 | 京都市上京区 | 西上善寺町 | 207 | 135.740488 | 35.029396 (5 rows) ``` -------------------------------- ### Geocode another address with geocoder() Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Geocodes another Japanese address using the geocoder function. The output shows a successful result with code 1 and the normalized address. ```sql select * from geocoder('神奈川県横浜市西区みなとみらい3−6−3'); ``` ```text code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+------------+-----------+---------------------------------+-----------+-------------+----------------+--------+---- 1 | 139.632805 | 35.458282 | 神奈川県横浜市西区みなとみらい三丁目6番 | 神奈川県 | 横浜市西区 | みなとみらい三丁目 | 6 | 3 (1 row) ``` -------------------------------- ### Reverse geocode with search distance using reverse_geocoder() Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Reverse geocodes a coordinate with a search distance of 50 meters. The third argument specifies the search radius in meters. ```sql select * from reverse_geocoder(141.342094, 43.050264, 50); ``` ```text code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+-------------------+-------------------+---------------------------------------+-----------+--------------+------------------+--------+---- 1 | 141.3421173095703 | 43.05035400390625 | 北海道札幌市中央区南七条西十一丁目4-5 | 北海道 | 札幌市中央区 | 南七条西十一丁目 | 4 | 5 (1 row) ``` -------------------------------- ### Geocode all addresses in table Source: https://github.com/mbasa/pggeocoder/wiki/Bulk-Geocoding Updates the 'gc' column by geocoding the 'address' column for every row in the table. ```sql UPDATE table_name SET gc = geocoder( address ); ``` -------------------------------- ### Display inserted addresses from trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Selects id and address from trigtable to show the inserted data. ```sql select id,address from trigtable; ``` -------------------------------- ### Output of geocoder data after update Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Shows the geocoding results after the update, with row 5 now geocoded to the new address. ```text code | todofuken | shikuchoson | ooaza | chiban | x | y ------+-----------+--------------+------------------+--------+------------+----------- 2 | 京都府 | 京都市上京区 | 馬喰町 | 885 | 135.736477 | 35.030054 2 | 京都府 | 京都市中京区 | 晴明町 | 673 | 135.765329 | 35.013509 2 | 京都府 | 京都市中京区 | 塩屋町 | 324 | 135.769512 | 35.005731 2 | 京都府 | 京都市中京区 | 下本能寺前町 | 492 | 135.767985 | 35.010143 2 | 北海道 | 札幌市白石区 | 東札幌五条五丁目 | 4 | 141.395119 | 43.049696 (5 rows) ``` -------------------------------- ### SQL view for geocoder layer Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service SQL statement for the GeoServer parametric SQL view that calls the geocoder function with an address parameter and returns a point geometry. ```sql SELECT todofuken,shikuchoson,ooaza,chiban,go,ST_POINT(x,y,4326) AS geom FROM geocoder( '%address%' ) ``` -------------------------------- ### Insert address data into trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Inserts five Japanese addresses into the trigtable. The trigger automatically geocodes each address. ```sql INSERT INTO trigtable (address) VALUES ('京都府京都市上京区御前通今出川上ル馬喰町885'), ('京都府京都市中京区二条通富小路東入晴明町673-2'), ('京都府京都市中京区河原町蛸薬師東側塩屋町324古城ビル地下1F'), ('京都府京都市中京区御池通寺町東入下本能寺前町492番地1他'), ('京都府京都市上京区今出川通六軒町西入西上善寺町207-6'); ``` -------------------------------- ### Create trigger trigtable_trigger1 Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Creates a BEFORE INSERT OR UPDATE trigger on trigtable that executes geocder_trigger_func for each row. ```sql CREATE TRIGGER trigtable_trigger1 BEFORE INSERT OR UPDATE ON trigtable FOR EACH ROW EXECUTE PROCEDURE geocder_trigger_func(); ``` -------------------------------- ### Reverse geocode coordinates with reverse_geocoder() Source: https://github.com/mbasa/pggeocoder/blob/master/README.md Reverse geocodes a coordinate (longitude, latitude) using the reverse_geocoder function. The output shows the nearest address and its administrative divisions. ```sql select * from reverse_geocoder(141.342094, 43.050264); ``` ```text code | x | y | address | todofuken | shikuchoson | ooaza | chiban | go ------+-------------------+-------------------+---------------------------------------+-----------+--------------+------------------+--------+---- 1 | 141.3421173095703 | 43.05035400390625 | 北海道札幌市中央区南七条西十一丁目4-5 | 北海道 | 札幌市中央区 | 南七条西十一丁目 | 4 | 5 (1 row) ``` -------------------------------- ### Create trigger function geocder_trigger_func Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Defines a PL/pgSQL trigger function that sets NEW.gc to the result of geocoder(NEW.address) when address is not null and not empty. Returns NEW to allow the row modification. ```sql CREATE OR REPLACE FUNCTION geocder_trigger_func() RETURNS TRIGGER LANGUAGE PLPGSQL AS $$ BEGIN IF NEW.address IS NOT NULL AND NEW.address <> '' THEN NEW.gc = geocoder(NEW.address); END IF; RETURN NEW; END; $$ ``` -------------------------------- ### Geocode addresses via dblink Source: https://github.com/mbasa/pggeocoder/wiki/Geocoding-from-Different-Database Calls the geocoder function in the addresses2020 database via dblink to geocode addresses from the taddr table. The dbname=addresses2020 parameter connects to that database. The output shows the geocoded results with coordinates and normalized addresses. ```sql select gc.code,gc.x,gc.y,a.address,gc.output_address from taddr a, dblink('dbname=addresses2020', format('select code,x,y,address from geocoder(''%s'')',a.address)) as gc(code int,x float,y float,output_address text); ``` ```text code | x | y | address | output_address ------+---------------+--------------+--------------------+------------------------- 5 | 140.723849549 | 41.764847246 | 函館市栄町7-3 | 北海道函館市栄町7-3 5 | 140.708756321 | 41.768591869 | 函館市大町4-4 | 北海道函館市大町4-4 5 | 140.970960237 | 42.315100519 | 室蘭市幸町7番6号 | 北海道室蘭市幸町7-6 5 | 140.751891535 | 41.785361264 | 函館市時任町8-5 | 北海道函館市時任町8-5 5 | 140.760768095 | 41.792977704 | 函館市柳町9番5号 | 北海道函館市柳町9-5 5 | 139.802139069 | 35.673290533 | 江東区冬木5-2 | 東京都江東区冬木5-2 5 | 139.6489284 | 35.78332249 | 板橋区大門7-5 | 東京都板橋区大門7-5 5 | 139.811179767 | 35.680283239 | 江東区石島4-4 | 東京都江東区石島4-4 5 | 139.815582756 | 35.680816736 | 江東区千田6-1 | 東京都江東区千田6-1 5 | 139.6995335 | 35.75216472 | 板橋区仲町1-4 | 東京都板橋区仲町1-4 5 | 135.424813079 | 34.822802778 | 池田市栄町3番3号 | 大阪府池田市栄町3-3 5 | 135.670882514 | 34.792646098 | 交野市松塚1番1号 | 大阪府交野市松塚1-1 5 | 135.567628291 | 34.748239101 | 守口市淀江町3-5 | 大阪府守口市淀江町3-5 5 | 135.559816044 | 34.732592095 | 守口市祝町9-18 | 大阪府守口市祝町9-18 5 | 135.425545386 | 34.823655372 | 池田市栄町7-13 | 大阪府池田市栄町7-13 5 | 127.9821749 | 26.591162107 | 名護市城1-1-3 | 沖縄県名護市城一丁目1-3 5 | 127.672455839 | 26.218052182 | 那覇市辻2-4-1 | 沖縄県那覇市辻二丁目4-1 5 | 127.673542041 | 26.213388049 | 那覇市東町26-1 | 沖縄県那覇市東町26-1 5 | 127.667601796 | 26.214933424 | 那覇市西3-4-1 | 沖縄県那覇市西三丁目4-1 5 | 127.66841311 | 26.203934604 | 那覇市山下町3-1 | 沖縄県那覇市山下町3-1 (20 rows) ``` -------------------------------- ### Add geores column for geocoding Source: https://github.com/mbasa/pggeocoder/wiki/Spatial-Analytics Adds a column of type geores to the tokyo_demo table to store pgGeocoder results. ```sql ALTER TABLE tokyo_demo ADD COLUMN gc geores; ``` -------------------------------- ### Update address in trigtable Source: https://github.com/mbasa/pggeocoder/wiki/Creating-Triggers-for-the-Geocoder Updates the address of row id=5 to a new address, triggering automatic re-geocoding. ```sql update trigtable set address = '北海道札幌市白石区東札幌五条5-4-30-2' where id = 5; ``` -------------------------------- ### Reverse Geocoder SQL View Statement Source: https://github.com/mbasa/pggeocoder/wiki/WMS-and-WFS-Service SQL statement for the Reverse Geocoder layer's SQL view. Uses the reverse_geocoder function with %lon% and %lat% parameters and returns a 4326-projected geometry. ```sql select code,todofuken,shikuchoson,ooaza,chiban,go,ST_POINT(x,y,4326) as geom from reverse_geocoder( %lon%, %lat% ) ``` -------------------------------- ### Add geores column to table Source: https://github.com/mbasa/pggeocoder/wiki/Bulk-Geocoding Adds a column named 'gc' of type 'geores' to an existing table to store geocoding results. ```sql ALTER TABLE table_name ADD COLUMN gc geores; ``` -------------------------------- ### Reverse geocode via dblink Source: https://github.com/mbasa/pggeocoder/wiki/Geocoding-from-Different-Database Calls the reverse_geocoder function in the addresses2020 database via dblink to reverse geocode a coordinate (139.811179767, 35.680283239). The output shows the corresponding address and administrative divisions. ```sql select * from dblink('dbname=addresses2020', format('select address,todofuken,shikuchoson,ooaza from reverse_geocoder(%L,%L);',139.811179767,35.680283239)) as gc(address text,todofuken text,shikuchoson text,ooaza text); ``` ```text address | todofuken | shikuchoson | ooaza ---------------------+-----------+-------------+------- 東京都江東区石島4-4 | 東京都 | 江東区 | 石島 (1 row) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.