Skip to content

Commit

Permalink
closes #11; updated to abr's new data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
mbasa committed May 29, 2024
1 parent c4c880f commit 73cd2da
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 60 deletions.
6 changes: 3 additions & 3 deletions scripts/import_abr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ psql -U ${DBROLE} -d ${DBNAME} -f ./sql/abr/dropABRTables.sql
# Create abr schema and tables
psql -U ${DBROLE} -d ${DBNAME} -f ./sql/abr/createABRTables.sql

RSDT_TABLE="abr.rsdtdsp_dsp (lg_code ,town_id ,blk_id ,addr_id ,addr2_id ,city_name ,od_city_name ,oaza_town_name ,chome_name ,koaza_name ,blk_num ,rsdt_num ,rsdt_num2 ,basic_rsdt_div ,rsdt_addr_flg ,rsdt_addr_mtd_code ,oaza_frn_ltrs_flg ,koaza_frn_ltrs_flg ,status_flg ,efct_date ,ablt_date ,src_code ,remarks )"
RSDT_POS_TABLE="abr.rsdtdsp_pos(lg_code ,town_id ,blk_id ,addr_id ,addr2_id ,disp_flag ,disp_method_flag ,basic_rsdt_div ,rep_pnt_lon ,rep_pnt_lat ,epsg ,scale ,source_url ,effective_date )"
PREF_TABLE="abr.pref (lg_code ,pref_name ,pref_name_kana ,pref_name_roma ,efct_date ,ablt_date ,remarks )"
RSDT_TABLE="abr.rsdtdsp_dsp (lg_code,machiaza_id,blk_id,rsdt_id,rsdt2_id,city,ward,oaza_cho,chome,koaza,machiaza_dist,blk_num,rsdt_num,rsdt_num2,basic_rsdt_div,rsdt_addr_flg,rsdt_addr_mtd_code,status_flg,efct_date,ablt_date,src_code,remarks)"
RSDT_POS_TABLE="abr.rsdtdsp_pos(lg_code,machiaza_id,blk_id,rsdt_id,rsdt2_id,rsdt_addr_flg,rsdt_addr_mtd_code,rep_lon,rep_lat,rep_srid,rep_scale,rep_src_code,rsdt_addr_code_rdbl,rsdt_addr_data_mnt_date,basic_rsdt_div)"
PREF_TABLE="abr.pref (lg_code,pref,pref_kana,pref_roma,efct_date,ablt_date,remarks)"


echo -e "\nImporting rsdt csv files..."
Expand Down
30 changes: 15 additions & 15 deletions sql/abr/convertABRTables.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
create index abrpos1 on abr.rsdtdsp_pos (lg_code);
create index abrpos2 on abr.rsdtdsp_pos (town_id);
create index abrpos2 on abr.rsdtdsp_pos (machiaza_id);
create index abrpos3 on abr.rsdtdsp_pos (blk_id);
create index abrpos4 on abr.rsdtdsp_pos (addr_id);
create index abrpos5 on abr.rsdtdsp_pos (addr2_id);
create index abrpos4 on abr.rsdtdsp_pos (rsdt_id);
create index abrpos5 on abr.rsdtdsp_pos (rsdt2_id);

create index abr1 on abr.rsdtdsp_dsp (lg_code);
create index abr2 on abr.rsdtdsp_dsp (town_id);
create index abr2 on abr.rsdtdsp_dsp (machiaza_id);
create index abr3 on abr.rsdtdsp_dsp (blk_id);
create index abr4 on abr.rsdtdsp_dsp (addr_id);
create index abr5 on abr.rsdtdsp_dsp (addr2_id);
create index abr4 on abr.rsdtdsp_dsp (rsdt_id);
create index abr5 on abr.rsdtdsp_dsp (rsdt2_id);

vacuum ANALYZE abr.rsdtdsp_pos ;
vacuum ANALYZE abr.rsdtdsp_dsp ;
Expand All @@ -17,18 +17,18 @@ delete from pggeocoder.address_g;

insert into pggeocoder.address_g (todofuken,shikuchoson,ooaza,chiban,go,lon,lat,geog)
select
pref_name as todofuken,
city_name||COALESCE(od_city_name,'') as shikuchoson,
COALESCE(oaza_town_name,'') || COALESCE(koaza_name,COALESCE(chome_name,'')) as ooza,
pref as todofuken,
city||COALESCE(ward,'') as shikuchoson,
COALESCE(oaza_cho,'') || COALESCE(koaza,COALESCE(chome,'')) as ooza,
blk_num as chiban,
rsdt_num as go,
b.rep_pnt_lon as lon,
b.rep_pnt_lat as lat,
st_point(b.rep_pnt_lon,b.rep_pnt_lat,4326) as geog
b.rep_lon as lon,
b.rep_lat as lat,
st_point(b.rep_lon::float,b.rep_lat::float,4326) as geog
from abr.rsdtdsp_dsp a,abr.rsdtdsp_pos b, abr.pref c
where a.lg_code = b.lg_code and
a.town_id = b.town_id and
a.machiaza_id = b.machiaza_id and
a.blk_id = b.blk_id and
a.addr_id = b.addr_id and
COALESCE(a.addr2_id,'') = COALESCE(b.addr2_id,'') and
a.rsdt_id = b.rsdt_id and
COALESCE(a.rsdt2_id,'') = COALESCE(b.rsdt2_id,'') and
substr(a.lg_code,1,2) = substr(c.lg_code,1,2);
84 changes: 42 additions & 42 deletions sql/abr/createABRTables.sql
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
create schema if not exists abr;

CREATE TABLE if not exists abr.rsdtdsp_dsp (
"lg_code" TEXT DEFAULT '',
"town_id" TEXT DEFAULT '',
"blk_id" TEXT DEFAULT '',
"addr_id" TEXT DEFAULT '',
"addr2_id" TEXT DEFAULT '',
"city_name" TEXT,
"od_city_name" TEXT,
"oaza_town_name" TEXT,
"chome_name" TEXT,
"koaza_name" TEXT,
"blk_num" TEXT,
"rsdt_num" TEXT,
"rsdt_num2" TEXT,
"basic_rsdt_div" TEXT,
"rsdt_addr_flg" TEXT,
"rsdt_addr_mtd_code" TEXT,
"oaza_frn_ltrs_flg" TEXT,
"koaza_frn_ltrs_flg" TEXT,
"status_flg" TEXT,
"efct_date" TEXT,
"ablt_date" TEXT,
"src_code" TEXT,
"remarks" TEXT
"lg_code" TEXT DEFAULT '',
"machiaza_id" TEXT DEFAULT '',
"blk_id" TEXT DEFAULT '',
"rsdt_id" TEXT DEFAULT '',
"rsdt2_id" TEXT DEFAULT '',
"city" TEXT DEFAULT '',
"ward" TEXT DEFAULT '',
"oaza_cho" TEXT DEFAULT '',
"chome" TEXT DEFAULT '',
"koaza" TEXT DEFAULT '',
"machiaza_dist" TEXT DEFAULT '',
"blk_num" TEXT DEFAULT '',
"rsdt_num" TEXT DEFAULT '',
"rsdt_num2" TEXT DEFAULT '',
"basic_rsdt_div" TEXT DEFAULT '',
"rsdt_addr_flg" TEXT DEFAULT '',
"rsdt_addr_mtd_code" TEXT DEFAULT '',
"status_flg" TEXT DEFAULT '',
"efct_date" TEXT DEFAULT '',
"ablt_date" TEXT DEFAULT '',
"src_code" TEXT DEFAULT '',
"remarks" TEXT DEFAULT ''
);

CREATE TABLE if not exists abr.rsdtdsp_pos (
"lg_code" TEXT DEFAULT '',
"town_id" TEXT DEFAULT '',
"blk_id" TEXT DEFAULT '',
"addr_id" TEXT DEFAULT '',
"addr2_id" TEXT DEFAULT '',
"disp_flag" TEXT,
"disp_method_flag" TEXT,
"basic_rsdt_div" TEXT,
"rep_pnt_lon" REAL,
"rep_pnt_lat" REAL,
"epsg" TEXT,
"scale" TEXT,
"source_url" TEXT,
"effective_date" TEXT
"lg_code" TEXT DEFAULT '',
"machiaza_id" TEXT DEFAULT '',
"blk_id" TEXT DEFAULT '',
"rsdt_id" TEXT DEFAULT '',
"rsdt2_id" TEXT DEFAULT '',
"rsdt_addr_flg" TEXT DEFAULT '',
"rsdt_addr_mtd_code" TEXT DEFAULT '',
"rep_lon" FLOAT,
"rep_lat" FLOAT,
"rep_srid" TEXT DEFAULT '',
"rep_scale" TEXT DEFAULT '',
"rep_src_code" TEXT DEFAULT '',
"rsdt_addr_code_rdbl" TEXT DEFAULT '',
"rsdt_addr_data_mnt_date" TEXT DEFAULT '',
"basic_rsdt_div" TEXT DEFAULT ''
);

CREATE TABLE IF NOT EXISTS abr.pref (
"lg_code" TEXT,
"pref_name" TEXT,
"pref_name_kana" TEXT,
"pref_name_roma" TEXT,
"lg_code" TEXT,
"pref" TEXT,
"pref_kana" TEXT,
"pref_roma" TEXT,
"efct_date" TEXT,
"ablt_date" TEXT,
"remarks" TEXT
"remarks" TEXT
);


Expand Down

0 comments on commit 73cd2da

Please sign in to comment.