From e3a48577331e93e3372ef0251db0f0e85484c86b Mon Sep 17 00:00:00 2001 From: Chris Henrick Date: Thu, 21 Aug 2014 15:42:41 -0400 Subject: [PATCH] update comments --- geocoder/admin1/sql/build_data_table.sql | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/geocoder/admin1/sql/build_data_table.sql b/geocoder/admin1/sql/build_data_table.sql index d59ec24..20704d6 100644 --- a/geocoder/admin1/sql/build_data_table.sql +++ b/geocoder/admin1/sql/build_data_table.sql @@ -4,14 +4,13 @@ -- for countries that have admin1 regions we use data from qs_adm1_region -------------------------------------------------------------- +--- only do this step global_id doesn't exist in quattro shapes admin1 datasets: --- add column global_id to admin1 and admin1 region tables ---- only do this if they don't exist: --ALTER TABLE qs_adm1 ADD COLUMN global_id INT; --ALTER TABLE qs_adm1_region ADD COLUMN global_id INT; ---- create a unique id for both the adm1 and adm1_region tables ---- first create new table in memory ---- use the cartodb_id with the table name +--- we need to create a unique id for both the adm1 and adm1_region tables +--- first create new table in memory. use the cartodb_id with the table name WITH all_data AS ( SELECT cartodb_id AS source_id, 'qs_adm1' AS sourcetable FROM qs_adm1 UNION ALL @@ -21,7 +20,7 @@ WITH all_data AS ( global_id AS ( SELECT *, ROW_NUMBER() OVER (ORDER BY source_id ASC) id FROM all_data ), ---- update both tables globa_id column +--- now update both tables' global_id column first_update AS ( UPDATE qs_adm1 SET global_id = ( SELECT id FROM global_id WHERE source_id = qs_adm1.cartodb_id AND sourcetable ='qs_adm1' @@ -32,8 +31,8 @@ first_update AS ( SELECT id FROM global_id WHERE source_id = qs_adm1_region.cartodb_id AND sourcetable ='qs_adm1_region' ); ---- punch out ne_10m coastline from the following countries in quattro shapes admin1 data one at a time to not bog down the cpu -update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'USA';--cartodb_id >= 0 AND cartodb_id < 20; +--- punch out ne_10m coastline from the following countries in quattro shapes admin1 data. Do this one at a time to not bog down the cpu. +update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'USA'; update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'CAN'; update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'MEX'; update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'SWE'; @@ -41,10 +40,10 @@ update qs_adm1_region set the_geom = ST_Intersection(the_geom, (SELECT the_geom update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'HRV'; update qs_adm1 set the_geom = ST_Intersection(the_geom, (SELECT the_geom FROM ne_10m_land)) WHERE qs_adm0_a3 = 'NOR'; ---- clear all existing data from the table +--- clear all existing data from the adm1 table DELETE FROM adm1; ---- insert data from quattro shapes adm1 where countries don't have Regions +--- insert data from quattro shapes adm1 where countries don't have admin1 regions INSERT INTO adm1 (the_geom, global_id) SELECT the_geom, global_id FROM qs_adm1 @@ -54,6 +53,3 @@ INSERT INTO adm1 (the_geom, global_id) INSERT INTO adm1 (the_geom, global_id) SELECT the_geom, global_id FROM qs_adm1_region; - - --- synonyms table = rank, isoCode, id, name, name_code \ No newline at end of file