mirror of
https://github.com/dataforcanada/d4c-datapkg-statistical.git
synced 2026-06-13 14:10:55 +02:00
Initial commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
# TODO
|
||||
- Process 2023 Federal Electoral Districts
|
||||
- For `load.sh`
|
||||
- Finish processing 2001 data
|
||||
|
||||
- For `country.sql`
|
||||
- Create `country_2001` from 2001 geometries. Need to finish `load.sh`
|
||||
- Add English abbreviation for all years
|
||||
- Add French abbreviation for all years
|
||||
|
||||
- For `geographic_regions_of_canada.sql`
|
||||
- Add other years (2016, 2011, 2006, 2001)
|
||||
- Add GRC abbreviation english
|
||||
- Add GRC abbreviation french
|
||||
- According to this, Territories DGUID should be `2021A00016` https://www150.statcan.gc.ca/n1/en/geo?geotext=Territories%20%5BRegion%5D&geocode=A00016
|
||||
- According to the link above, British Columbia DGUID should be `2021A00015`
|
||||
|
||||
- For `er_2021`, split `er_name` into English and French components. There's some records that are separated by `/`
|
||||
- South Coast--Burin Peninsula / Côte-sud--Burin Peninsula
|
||||
- West Coast--Northern Peninsula--Labrador / Côte-ouest--Northern Peninsula--Labrador
|
||||
- Prince Edward Island / Île-du-Prince-Édouard
|
||||
|
||||
- For `cma_2021`, split `cma_name` into English and French components. There's some records that are separated by `/`
|
||||
- Greater Sudbury / Grand Sudbury
|
||||
- Ottawa - Gatineau (Ontario part / partie de l'Ontario)
|
||||
|
||||
- For `ccs_2021`, split `ccs_name` into English and French components. There's some records that are separated by `/`
|
||||
- West Nipissing / Nipissing Ouest
|
||||
- French River / Rivière des Français
|
||||
- Greater Sudbury / Grand Sudbury
|
||||
- The Nation / La Nation
|
||||
|
||||
- For `csd_2021`, split `csd_name` into English and French components. There's some records that are separated by `/`
|
||||
- The Nation / La Nation
|
||||
- West Nipissing / Nipissing Ouest
|
||||
- Greater Sudbury / Grand Sudbury
|
||||
- Beaubassin East / Beaubassin-est
|
||||
|
||||
- For `csd_2021`, figure out what level of geography the sac_code and sac_type belongs to so I can name it appropriately
|
||||
|
||||
- For `pop_ctr_2021`, split `pop_ctr_name` into English and French components. There's one record that is separated by `/`
|
||||
- Grand Falls / Grand-Sault
|
||||
|
||||
- For `dpl_2021`, split `dpl_name` into English and French components. There's records that are separated by `/`
|
||||
- Saint Irénée and Alderwood / Saint Irénée et Alderwood
|
||||
- `Sainte-Anne-de-Kent part B / partie B` - this one would need to be split into `Sainte-Anne-de-Kent part B` and `Sainte-Anne-de-Kentpartie partie B`
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
Aggregate Dissemination Areas
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240731061904/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo053
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.ada_2021;
|
||||
CREATE TABLE silver.ada_2021 AS
|
||||
SELECT DISTINCT
|
||||
cd.country_dguid,
|
||||
cd.country_en_name,
|
||||
cd.country_fr_name,
|
||||
cd.country_en_abbreviation,
|
||||
cd.country_fr_abbreviation,
|
||||
cd.grc_dguid,
|
||||
cd.grc_en_name,
|
||||
cd.grc_fr_name,
|
||||
cd.pr_dguid,
|
||||
cd.pr_en_name,
|
||||
cd.pr_fr_name,
|
||||
cd.pr_en_abbreviation,
|
||||
cd.pr_fr_abbreviation,
|
||||
cd.pr_iso_code,
|
||||
cd.car_dguid,
|
||||
cd.car_en_name,
|
||||
cd.car_fr_name,
|
||||
cd.cd_dguid,
|
||||
cd.cd_name,
|
||||
cd.cd_type,
|
||||
cma.cma_dguid,
|
||||
cma.cma_p_dguid,
|
||||
cma.cma_name,
|
||||
cma.cma_type,
|
||||
dgr.ada_dguid,
|
||||
ada.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN silver.cd_2021 AS cd
|
||||
ON dgr.cd_dguid = cd.cd_dguid
|
||||
LEFT JOIN silver.cma_2021 AS cma
|
||||
ON
|
||||
concat(dgr.cma_dguid, dgr.cma_p_dguid)
|
||||
= concat(cma.cma_dguid, cma.cma_p_dguid)
|
||||
LEFT JOIN bronze.lada000a21a_e AS ada
|
||||
ON dgr.ada_dguid = ada.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.ada_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX ada_2021_geom_idx ON silver.ada_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,16 @@
|
||||
# https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2001-eng.cfm
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gpr_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gpr_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gfed000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gfed000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/ger_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/ger_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gcd_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcd_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gcar000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcar000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gccs000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gccs000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gcsd000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcsd000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gcma000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcma000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gct_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gct_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gda_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gda_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gdb_000a01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdb_000a01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gdpl000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdpl000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gua_000b01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gua_000b01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/gecu000e01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gecu000e01m_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2001/geca000e01m_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/geca000e01m_e.zip
|
||||
@@ -0,0 +1,16 @@
|
||||
# https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2006-eng.cfm
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gpr_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gpr_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gfed000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gfed000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/ger_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/ger_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gcd_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcd_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gcar000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcar000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gccs000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gccs000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gcsd000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcsd000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gcma000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcma000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gct_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gct_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gda_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gda_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gdb_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdb_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gdpl000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdpl000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gua_000a06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gua_000a06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/gecu000e06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gecu000e06a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2006/geca000e06a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/geca000e06a_e.zip
|
||||
@@ -0,0 +1,17 @@
|
||||
# https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gpr_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gpr_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gfed000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gfed000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/ger_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/ger_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gcd_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcd_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gcar000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcar000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gccs000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gccs000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gcsd000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcsd000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gcma000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gcma000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gct_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gct_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gda_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gda_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gdb_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdb_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gdpl000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gdpl000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gpc_000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gpc_000a11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gecu000e11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gecu000e11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/geca000e11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/geca000e11a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2011/gfsa000a11a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/gfsa000a11a_e.zip
|
||||
@@ -0,0 +1,18 @@
|
||||
# https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2016-eng.cfm
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lpr_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lpr_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lfed000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfed000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/ler_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/ler_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lcd_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lcd_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lada000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lada000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lcar000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lcar000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lccs000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lccs000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lcsd000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lcsd000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lcma000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lcma000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lct_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lct_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lda_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lda_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/ldb_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/ldb_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/ldpl000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/ldpl000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lpc_000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lpc_000a16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lecu000e16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lecu000e16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/geca000e16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/geca000e16a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2016/lfsa000a16a_e.zip https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/files-fichiers/2016/lfsa000a16a_e.zip
|
||||
@@ -0,0 +1,18 @@
|
||||
# https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/index2021-eng.cfm?year=21
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lpr_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lpr_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lcd_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lcd_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lfed000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lfed000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lcsd000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lcsd000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/ldpl000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/ldpl000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lfsa000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lfsa000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/ler_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/ler_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lcar000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lcar000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lccs000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lccs000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lcma000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lcma000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lct_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lct_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lpc_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lpc_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lda_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lda_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/ldb_000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/ldb_000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lada000a21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lada000a21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/lecu000e21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/lecu000e21a_e.zip
|
||||
https://data.dataforcanada.org/archive/statistics_canada/boundaries/2021/leca000e21a_e.zip https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/files-fichiers/leca000e21a_e.zip
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Census Agricultural Regions
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250401192328/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=geo006
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.car_2021;
|
||||
CREATE TABLE silver.car_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
dgr.car_dguid,
|
||||
car.carename AS car_en_name,
|
||||
car.carfname AS car_fr_name,
|
||||
car.geom
|
||||
FROM
|
||||
silver.pr_2021 AS pr,
|
||||
silver.dissemination_geographies_relationship_2021 AS dgr,
|
||||
bronze.lcar000a21a_e AS car
|
||||
WHERE
|
||||
pr.pr_dguid = dgr.pr_dguid
|
||||
AND car.dguid = dgr.car_dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.car_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX car_2021_geom_idx ON silver.car_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
Census Consolidated Subdivisions
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250401192303/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo007
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.ccs_2021;
|
||||
CREATE TABLE silver.ccs_2021 AS
|
||||
SELECT DISTINCT
|
||||
cd.country_dguid,
|
||||
cd.country_en_name,
|
||||
cd.country_fr_name,
|
||||
cd.country_en_abbreviation,
|
||||
cd.country_fr_abbreviation,
|
||||
cd.grc_dguid,
|
||||
cd.grc_en_name,
|
||||
cd.grc_fr_name,
|
||||
cd.pr_dguid,
|
||||
cd.pr_en_name,
|
||||
cd.pr_fr_name,
|
||||
cd.pr_en_abbreviation,
|
||||
cd.pr_fr_abbreviation,
|
||||
cd.pr_iso_code,
|
||||
cd.car_dguid,
|
||||
cd.car_en_name,
|
||||
cd.car_fr_name,
|
||||
cd.cd_dguid,
|
||||
cd.cd_name,
|
||||
cd.cd_type,
|
||||
ccs.dguid AS ccs_dguid,
|
||||
ccs.ccsname AS ccs_name,
|
||||
ccs.geom
|
||||
FROM
|
||||
silver.cd_2021 AS cd,
|
||||
silver.dissemination_geographies_relationship_2021 AS dgr,
|
||||
bronze.lccs000a21a_e AS ccs
|
||||
WHERE
|
||||
cd.cd_dguid = dgr.cd_dguid
|
||||
AND
|
||||
ccs.dguid = dgr.ccs_dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.ccs_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX ccs_2021_geom_idx ON silver.ccs_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
Census Divisions
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250131082459/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=geo008#moreinfo
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.cd_2021;
|
||||
CREATE TABLE silver.cd_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
dgr.car_dguid,
|
||||
car.carename AS car_en_name,
|
||||
car.carfname AS car_fr_name,
|
||||
cd.dguid AS cd_dguid,
|
||||
cd.cdname AS cd_name,
|
||||
cd.cdtype AS cd_type,
|
||||
cd.geom
|
||||
FROM
|
||||
silver.pr_2021 AS pr,
|
||||
bronze.lcd_000a21a_e AS cd,
|
||||
silver.dissemination_geographies_relationship_2021 AS dgr,
|
||||
bronze.lcar000a21a_e AS car
|
||||
WHERE
|
||||
pr.pr_dguid = dgr.pr_dguid
|
||||
AND cd.dguid = dgr.cd_dguid
|
||||
AND dgr.car_dguid = car.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.cd_2021
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX cd_2021_geom_idx ON silver.cd_2021
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
/* 2016
|
||||
Definition here: https://web.archive.org/web/20250304001456/https://www12.statcan.gc.ca/census-recensement/2016/ref/dict/geo008-eng.cfm
|
||||
*/
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
Census Metropolitan Areas
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250518133322/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo009
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.cma_2021;
|
||||
CREATE TABLE silver.cma_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
cma.dguid AS cma_dguid,
|
||||
cma.dguidp AS cma_p_dguid,
|
||||
cma.cmaname AS cma_name,
|
||||
cma.cmatype AS cma_type,
|
||||
cma.geom
|
||||
FROM
|
||||
silver.pr_2021 AS pr,
|
||||
bronze.lcma000a21a_e AS cma,
|
||||
silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
WHERE
|
||||
pr.pr_dguid = dgr.pr_dguid
|
||||
AND
|
||||
concat(
|
||||
cma.dguid,
|
||||
cma.dguidp) = concat(
|
||||
dgr.cma_dguid,
|
||||
dgr.cma_p_dguid
|
||||
);
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.cma_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX cma_2021_geom_idx ON silver.cma_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
Census Subdivisions
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240526213705/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo012
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.csd_2021;
|
||||
CREATE TABLE silver.csd_2021 AS
|
||||
SELECT DISTINCT
|
||||
cd.country_dguid,
|
||||
cd.country_en_name,
|
||||
cd.country_fr_name,
|
||||
cd.country_en_abbreviation,
|
||||
cd.country_fr_abbreviation,
|
||||
cd.grc_dguid,
|
||||
cd.grc_en_name,
|
||||
cd.grc_fr_name,
|
||||
cd.pr_dguid,
|
||||
cd.pr_en_name,
|
||||
cd.pr_fr_name,
|
||||
cd.pr_en_abbreviation,
|
||||
cd.pr_fr_abbreviation,
|
||||
cd.pr_iso_code,
|
||||
cd.car_dguid,
|
||||
cd.car_en_name,
|
||||
cd.car_fr_name,
|
||||
er.er_dguid,
|
||||
er.er_name,
|
||||
cd.cd_dguid,
|
||||
cd.cd_name,
|
||||
cd.cd_type,
|
||||
ccs.ccs_dguid,
|
||||
ccs.ccs_name,
|
||||
gaf.cma_dguid,
|
||||
gaf.cma_p_dguid,
|
||||
cma.cma_name,
|
||||
cma.cma_type,
|
||||
gaf.csd_dguid,
|
||||
csd.csdname AS csd_name,
|
||||
csd.csdtype AS csd_type,
|
||||
gaf.sac_type,
|
||||
gaf.sac_code,
|
||||
csd.geom
|
||||
FROM silver.gaf_2021 AS gaf
|
||||
LEFT JOIN silver.cma_2021 AS cma
|
||||
ON
|
||||
concat(gaf.cma_dguid, gaf.cma_p_dguid)
|
||||
= concat(cma.cma_dguid, cma.cma_p_dguid)
|
||||
LEFT JOIN silver.cd_2021 AS cd
|
||||
ON gaf.cd_dguid = cd.cd_dguid
|
||||
LEFT JOIN silver.er_2021 AS er
|
||||
ON gaf.er_dguid = er.er_dguid
|
||||
LEFT JOIN silver.ccs_2021 AS ccs
|
||||
ON gaf.ccs_dguid = ccs.ccs_dguid
|
||||
LEFT JOIN bronze.lcsd000a21a_e AS csd
|
||||
ON gaf.csd_dguid = csd.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.csd_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX csd_2021_geom_idx ON silver.csd_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Census Tracts
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20241013011815/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo013
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.ct_2021;
|
||||
CREATE TABLE silver.ct_2021 AS
|
||||
SELECT DISTINCT
|
||||
cma.country_dguid,
|
||||
cma.country_en_name,
|
||||
cma.country_fr_name,
|
||||
cma.country_en_abbreviation,
|
||||
cma.country_fr_abbreviation,
|
||||
cma.grc_dguid,
|
||||
cma.grc_en_name,
|
||||
cma.grc_fr_name,
|
||||
cma.pr_dguid,
|
||||
cma.pr_en_name,
|
||||
cma.pr_fr_name,
|
||||
cma.pr_en_abbreviation,
|
||||
cma.pr_fr_abbreviation,
|
||||
cma.pr_iso_code,
|
||||
cma.cma_dguid,
|
||||
cma.cma_p_dguid,
|
||||
cma.cma_name,
|
||||
cma.cma_type,
|
||||
ct.dguid AS ct_dguid,
|
||||
ct.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN bronze.lct_000a21a_e AS ct
|
||||
ON dgr.ct_dguid = ct.dguid
|
||||
LEFT JOIN silver.cma_2021 AS cma
|
||||
ON
|
||||
concat(dgr.cma_dguid, dgr.cma_p_dguid)
|
||||
= concat(cma.cma_dguid, cma.cma_p_dguid)
|
||||
WHERE dgr.ct_dguid IS NOT null;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.ct_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX ct_2021_geom_idx ON silver.ct_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
Canada
|
||||
*/
|
||||
|
||||
-- 2021 Canada;
|
||||
DROP TABLE IF EXISTS silver.country_2021;
|
||||
CREATE TABLE silver.country_2021 AS
|
||||
SELECT DISTINCT
|
||||
'2021A000011124' AS country_dguid,
|
||||
'Canada' AS country_en_name,
|
||||
'Canada' AS country_fr_name,
|
||||
'CAN' AS country_en_abbreviation,
|
||||
'CAN' AS country_fr_abbreviation,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.country_2021
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX country_2021_geom_idx ON silver.country_2021
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2016 Canada;
|
||||
DROP TABLE IF EXISTS silver.country_2016;
|
||||
CREATE TABLE silver.country_2016 AS
|
||||
SELECT DISTINCT
|
||||
'2016A000011124' AS country_dguid,
|
||||
'Canada' AS country_en_name,
|
||||
'Canada' AS country_fr_name,
|
||||
'CAN' AS country_en_abbreviation,
|
||||
'CAN' AS country_fr_abbreviation,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.country_2016
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX country_2016_geom_idx ON silver.country_2016
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2011 Canada;
|
||||
DROP TABLE IF EXISTS silver.country_2011;
|
||||
CREATE TABLE silver.country_2011 AS
|
||||
SELECT DISTINCT
|
||||
'2011A000011124' AS country_dguid,
|
||||
'Canada' AS country_en_name,
|
||||
'Canada' AS country_fr_name,
|
||||
'CAN' AS country_en_abbreviation,
|
||||
'CAN' AS country_fr_abbreviation,
|
||||
st_union(geom) AS geom
|
||||
FROM
|
||||
bronze.gpr_000a11a_e;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.country_2011
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX country_2011_geom_idx ON silver.country_2011
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2006 Canada;
|
||||
DROP TABLE IF EXISTS silver.country_2006;
|
||||
CREATE TABLE silver.country_2006 AS
|
||||
SELECT DISTINCT
|
||||
'2006A000011124' AS country_dguid,
|
||||
'Canada' AS country_en_name,
|
||||
'Canada' AS country_fr_name,
|
||||
'CAN' AS country_en_abbreviation,
|
||||
'CAN' AS country_fr_abbreviation,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.gpr_000a06a_e;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.country_2006
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX country_2006_geom_idx ON silver.country_2006
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2001 Canada;
|
||||
-- TODO
|
||||
/*
|
||||
-- Clean Provinces and Territories layer;
|
||||
UPDATE
|
||||
bronze.gpr_000a06a_e
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
DROP TABLE IF EXISTS country_2001;
|
||||
|
||||
CREATE TABLE country_2001 AS
|
||||
SELECT
|
||||
DISTINCT '2001A000011124' AS country_dguid,
|
||||
'Canada' AS country_en_name,
|
||||
'Canada' AS country_fr_name,
|
||||
'CAN' AS country_en_abbreviation,
|
||||
'CAN' AS country_fr_abbreviation,
|
||||
st_union(geom) AS geom
|
||||
FROM
|
||||
lpr_000a21a_e;
|
||||
|
||||
CREATE INDEX country_2001_geom_idx ON
|
||||
country_2001
|
||||
USING GIST(geom) WITH (FILLFACTOR = 100);
|
||||
*/
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
Designated Places
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240731061904/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo018
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.dpl_2021;
|
||||
CREATE TABLE silver.dpl_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
dgr.dpl_dguid,
|
||||
dpl.dplname AS dpl_name,
|
||||
dpl.dpltype AS dpl_type,
|
||||
dpl.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN silver.pr_2021 AS pr
|
||||
ON dgr.pr_dguid = pr.pr_dguid
|
||||
LEFT JOIN bronze.ldpl000a21a_e AS dpl
|
||||
ON dgr.dpl_dguid = dpl.dguid
|
||||
WHERE dgr.dpl_dguid IS NOT null;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.dpl_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX dpl_2021_geom_idx ON silver.dpl_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Dissemination Areas
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240731061905/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=geo021
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.da_2021;
|
||||
CREATE TABLE silver.da_2021 AS
|
||||
SELECT DISTINCT
|
||||
csd.country_dguid,
|
||||
csd.country_en_name,
|
||||
csd.country_fr_name,
|
||||
csd.country_en_abbreviation,
|
||||
csd.country_fr_abbreviation,
|
||||
csd.grc_dguid,
|
||||
csd.grc_en_name,
|
||||
csd.grc_fr_name,
|
||||
csd.pr_dguid,
|
||||
csd.pr_en_name,
|
||||
csd.pr_fr_name,
|
||||
csd.pr_en_abbreviation,
|
||||
csd.pr_fr_abbreviation,
|
||||
csd.pr_iso_code,
|
||||
csd.car_dguid,
|
||||
csd.car_en_name,
|
||||
csd.car_fr_name,
|
||||
csd.er_dguid,
|
||||
csd.er_name,
|
||||
csd.cd_dguid,
|
||||
csd.cd_name,
|
||||
csd.cd_type,
|
||||
csd.ccs_dguid,
|
||||
csd.ccs_name,
|
||||
csd.cma_dguid,
|
||||
csd.cma_p_dguid,
|
||||
csd.cma_name,
|
||||
csd.cma_type,
|
||||
csd.csd_dguid,
|
||||
csd.csd_name,
|
||||
csd.csd_type,
|
||||
csd.sac_type,
|
||||
csd.sac_code,
|
||||
dgr.ct_dguid,
|
||||
dgr.ada_dguid,
|
||||
dgr.da_dguid,
|
||||
da.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN silver.csd_2021 AS csd
|
||||
ON dgr.csd_dguid = csd.csd_dguid
|
||||
LEFT JOIN bronze.lda_000a21a_e AS da
|
||||
ON dgr.da_dguid = da.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
bronze.lda_000a21a_e
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX da_2021_geom_idx ON silver.da_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
Dissemination Blocks
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250212081621/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=geo014
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.db_2021;
|
||||
CREATE TABLE silver.db_2021 AS
|
||||
SELECT DISTINCT
|
||||
csd.country_dguid,
|
||||
csd.country_en_name,
|
||||
csd.country_fr_name,
|
||||
csd.country_en_abbreviation,
|
||||
csd.country_fr_abbreviation,
|
||||
csd.grc_dguid,
|
||||
csd.grc_en_name,
|
||||
csd.grc_fr_name,
|
||||
csd.pr_dguid,
|
||||
csd.pr_en_name,
|
||||
csd.pr_fr_name,
|
||||
csd.pr_en_abbreviation,
|
||||
csd.pr_fr_abbreviation,
|
||||
csd.pr_iso_code,
|
||||
csd.car_dguid,
|
||||
csd.car_en_name,
|
||||
csd.car_fr_name,
|
||||
csd.er_dguid,
|
||||
csd.er_name,
|
||||
csd.cd_dguid,
|
||||
csd.cd_name,
|
||||
csd.cd_type,
|
||||
csd.ccs_dguid,
|
||||
csd.ccs_name,
|
||||
csd.cma_dguid,
|
||||
csd.cma_p_dguid,
|
||||
csd.cma_name,
|
||||
csd.cma_type,
|
||||
csd.csd_dguid,
|
||||
csd.csd_name,
|
||||
csd.csd_type,
|
||||
csd.sac_type,
|
||||
csd.sac_code,
|
||||
dgr.fed_dguid,
|
||||
fed.fed_name,
|
||||
fed.fed_en_name,
|
||||
fed.fed_fr_name,
|
||||
dgr.ct_dguid,
|
||||
dgr.ada_dguid,
|
||||
dgr.da_dguid,
|
||||
dgr.db_dguid,
|
||||
db.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN silver.csd_2021 AS csd
|
||||
ON dgr.csd_dguid = csd.csd_dguid
|
||||
LEFT JOIN silver.fed_2021 AS fed
|
||||
ON dgr.fed_dguid = fed.fed_dguid
|
||||
LEFT JOIN bronze.ldb_000a21a_e AS db
|
||||
ON dgr.db_dguid = db.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.db_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX db_2021_geom_idx ON silver.db_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
Executable
+19
@@ -0,0 +1,19 @@
|
||||
#!/bin/bash
|
||||
if [ ! -d "${DATA_FOLDER}/boundaries" ]
|
||||
then
|
||||
echo "Making directory ${DATA_FOLDER}/boundaries/"
|
||||
mkdir -p ${DATA_FOLDER}/boundaries/{input,extracted,output}/{2021,2016,2011,2001}
|
||||
fi
|
||||
|
||||
INPUT_FOLDER="${DATA_FOLDER}/boundaries/input"
|
||||
|
||||
echo "Downloading 2021 boundaries"
|
||||
aria2c -x16 -i "${SCRIPT_DIR}/boundaries/boundary_files_2021.txt" --dir=${INPUT_FOLDER}/2021 --auto-file-renaming=false
|
||||
echo "Downloading 2016 boundaries"
|
||||
aria2c -x16 -i "${SCRIPT_DIR}/boundaries/boundary_files_2016.txt" --dir=${INPUT_FOLDER}/2016 --auto-file-renaming=false
|
||||
echo "Downloading 2011 boundaries"
|
||||
aria2c -x16 -i "${SCRIPT_DIR}/boundaries/boundary_files_2011.txt" --dir=${INPUT_FOLDER}/2011 --auto-file-renaming=false
|
||||
echo "Downloading 2006 boundaries"
|
||||
aria2c -x16 -i "${SCRIPT_DIR}/boundaries/boundary_files_2006.txt" --dir=${INPUT_FOLDER}/2006 --auto-file-renaming=false
|
||||
echo "Downloading 2001 boundaries"
|
||||
aria2c -x16 -i "${SCRIPT_DIR}/boundaries/boundary_files_2001.txt" --dir=${INPUT_FOLDER}/2001 --auto-file-renaming=false
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Economic Regions
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250518132130/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo022
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.er_2021;
|
||||
CREATE TABLE silver.er_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
er.dguid AS er_dguid,
|
||||
er.ername AS er_name,
|
||||
er.geom
|
||||
FROM
|
||||
silver.pr_2021 AS pr,
|
||||
silver.dissemination_geographies_relationship_2021 AS dgr,
|
||||
bronze.ler_000a21a_e AS er
|
||||
WHERE
|
||||
pr.pr_dguid = dgr.pr_dguid
|
||||
AND
|
||||
er.dguid = dgr.er_dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.er_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX er_2021_geom_idx ON silver.er_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Federal Electoral Districts
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240731061905/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo025
|
||||
*/
|
||||
|
||||
-- 2021 vintage, 2013 representation order;
|
||||
DROP TABLE IF EXISTS silver.fed_2021_2013;
|
||||
CREATE TABLE silver.fed_2021_2013 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
dgr.fed_dguid,
|
||||
fed.fedname AS fed_name,
|
||||
fed.fedename AS fed_en_name,
|
||||
fed.fedfname AS fed_fr_name,
|
||||
fed.geom
|
||||
FROM silver.dissemination_geographies_relationship_2021 AS dgr
|
||||
LEFT JOIN silver.pr_2021 AS pr
|
||||
ON dgr.pr_dguid = pr.pr_dguid
|
||||
LEFT JOIN bronze.lfed000a21a_e AS fed
|
||||
ON dgr.fed_dguid = fed.dguid
|
||||
WHERE dgr.fed_dguid IS NOT null;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.fed_2021_2013
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX fed_2021_2013_geom_idx ON silver.fed_2021_2013 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
Forward Sortation Areas
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20241102112247/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/Definition-eng.cfm?ID=geo036
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.fsa_2021;
|
||||
CREATE TABLE silver.fsa_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
fsa.dguid AS fsa_dguid,
|
||||
fsa.geom
|
||||
FROM bronze.lfsa000a21a_e AS fsa,
|
||||
silver.pr_2021 AS pr
|
||||
WHERE concat('2021A0002', fsa.pruid) = pr.pr_dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.fsa_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX fsa_2021_geom_idx ON silver.fsa_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
@@ -0,0 +1,471 @@
|
||||
/*
|
||||
Geographic Regions of Canada
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240624230708/https://www150.statcan.gc.ca/n1/pub/92-195-x/2021001/geo/region/region-eng.htm
|
||||
*/
|
||||
|
||||
-- With geometries;
|
||||
DROP TABLE IF EXISTS silver.grc_2021;
|
||||
CREATE TABLE silver.grc_2021 AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2021A00016' AS grc_dguid,
|
||||
'Territories' AS grc_en_name,
|
||||
'Territoires' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('60', '61', '62')
|
||||
),
|
||||
|
||||
atlantic AS (
|
||||
SELECT
|
||||
'2021A00011' AS grc_dguid,
|
||||
'Atlantic' AS grc_en_name,
|
||||
'Atlantique' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('10', '11', '12', '13')
|
||||
),
|
||||
|
||||
prairies AS (
|
||||
SELECT
|
||||
'2021A00014' AS grc_dguid,
|
||||
'Prairies' AS grc_en_name,
|
||||
'Prairies' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('48', '47', '46')
|
||||
),
|
||||
|
||||
the_rest AS (
|
||||
SELECT
|
||||
CASE
|
||||
WHEN pruid = '59' THEN '2021A00015'
|
||||
WHEN pruid = '35' THEN '2021A00013'
|
||||
WHEN pruid = '24' THEN '2021A00012'
|
||||
END AS grc_dguid,
|
||||
prename AS grc_en_name,
|
||||
prfname AS grc_fr_name,
|
||||
geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('59', '35', '24')
|
||||
),
|
||||
|
||||
final AS (
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2021 AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2021
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2021_geom_idx ON silver.grc_2021
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2021 without geometries, and with pr_dguid;
|
||||
DROP TABLE IF EXISTS silver.grc_pr_2021;
|
||||
CREATE TABLE silver.grc_pr_2021 AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2021A00016' AS grc_dguid,
|
||||
'Territories' AS grc_en_name,
|
||||
'Territoires' AS grc_fr_name,
|
||||
dguid AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('60', '61', '62')
|
||||
),
|
||||
|
||||
atlantic AS (
|
||||
SELECT
|
||||
'2021A00011' AS grc_dguid,
|
||||
'Atlantic' AS grc_en_name,
|
||||
'Atlantique' AS grc_fr_name,
|
||||
dguid AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('10', '11', '12', '13')
|
||||
),
|
||||
|
||||
prairies AS (
|
||||
SELECT
|
||||
'2021A00014' AS grc_dguid,
|
||||
'Prairies' AS grc_en_name,
|
||||
'Prairies' AS grc_fr_name,
|
||||
dguid AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('48', '47', '46')
|
||||
),
|
||||
|
||||
the_rest AS (
|
||||
SELECT
|
||||
CASE
|
||||
WHEN pruid = '59' THEN '2021A00015'
|
||||
WHEN pruid = '35' THEN '2021A00013'
|
||||
WHEN pruid = '24' THEN '2021A00012'
|
||||
END AS grc_dguid,
|
||||
prename AS grc_en_name,
|
||||
prfname AS grc_fr_name,
|
||||
dguid AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a21a_e
|
||||
WHERE
|
||||
pruid IN ('59', '35', '24')
|
||||
),
|
||||
|
||||
final AS (
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2021 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2021 AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
/* 2016
|
||||
Definition here: https://web.archive.org/web/20240224030001/https://www12.statcan.gc.ca/census-recensement/2016/ref/dict/geo027a-eng.cfm
|
||||
*/
|
||||
|
||||
-- With geometries;
|
||||
DROP TABLE IF EXISTS silver.grc_2016;
|
||||
CREATE TABLE silver.grc_2016 AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2016A00016' AS grc_dguid,
|
||||
'Territories' AS grc_en_name,
|
||||
'Territoires' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('60', '61', '62')
|
||||
),
|
||||
|
||||
atlantic AS (
|
||||
SELECT
|
||||
'2016A00011' AS grc_dguid,
|
||||
'Atlantic' AS grc_en_name,
|
||||
'Atlantique' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('10', '11', '12', '13')
|
||||
),
|
||||
|
||||
prairies AS (
|
||||
SELECT
|
||||
'2016A00014' AS grc_dguid,
|
||||
'Prairies' AS grc_en_name,
|
||||
'Prairies' AS grc_fr_name,
|
||||
ST_UNION(geom) AS geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('48', '47', '46')
|
||||
),
|
||||
|
||||
the_rest AS (
|
||||
SELECT
|
||||
CASE
|
||||
WHEN pruid = '59' THEN '2016A00015'
|
||||
WHEN pruid = '35' THEN '2016A00013'
|
||||
WHEN pruid = '24' THEN '2016A00012'
|
||||
END AS grc_dguid,
|
||||
prename AS grc_en_name,
|
||||
prfname AS grc_fr_name,
|
||||
geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('59', '35', '24')
|
||||
),
|
||||
|
||||
final AS (
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2016 AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2016
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2016_geom_idx ON silver.grc_2016
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2016 without geometries, and with pr_dguid;
|
||||
DROP TABLE IF EXISTS silver.grc_pr_2016;
|
||||
|
||||
CREATE TABLE silver.grc_pr_2016 AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2016A00016' AS grc_dguid,
|
||||
'Territories' AS grc_en_name,
|
||||
'Territoires' AS grc_fr_name,
|
||||
CONCAT('2016A0002', pruid) AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('60', '61', '62')
|
||||
),
|
||||
|
||||
atlantic AS (
|
||||
SELECT
|
||||
'2016A00011' AS grc_dguid,
|
||||
'Atlantic' AS grc_en_name,
|
||||
'Atlantique' AS grc_fr_name,
|
||||
CONCAT('2016A0002', pruid) AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('10', '11', '12', '13')
|
||||
),
|
||||
|
||||
prairies AS (
|
||||
SELECT
|
||||
'2016A00014' AS grc_dguid,
|
||||
'Prairies' AS grc_en_name,
|
||||
'Prairies' AS grc_fr_name,
|
||||
CONCAT('2016A0002', pruid) AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('48', '47', '46')
|
||||
),
|
||||
|
||||
the_rest AS (
|
||||
SELECT
|
||||
CASE
|
||||
WHEN pruid = '59' THEN '2016A00015'
|
||||
WHEN pruid = '35' THEN '2016A00013'
|
||||
WHEN pruid = '24' THEN '2016A00012'
|
||||
END AS grc_dguid,
|
||||
prename AS grc_en_name,
|
||||
prfname AS grc_fr_name,
|
||||
CONCAT('2016A0002', pruid) AS pr_dguid
|
||||
FROM
|
||||
bronze.lpr_000a16a_e
|
||||
WHERE
|
||||
pruid IN ('59', '35', '24')
|
||||
),
|
||||
|
||||
final AS (
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2016 AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
country.country_en_name,
|
||||
country.country_fr_name,
|
||||
country.country_en_abbreviation,
|
||||
country.country_fr_abbreviation,
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2016 AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
/* 2011
|
||||
Definition here: https://web.archive.org/web/20240214024306/https://www12.statcan.gc.ca/census-recensement/2011/ref/dict/geo027a-eng.cfm
|
||||
*/
|
||||
|
||||
/*
|
||||
2006
|
||||
No definition in 2006 dictionary https://www12.statcan.gc.ca/census-recensement/2006/ref/dict/azindex-eng.cfm
|
||||
*/
|
||||
|
||||
/*
|
||||
2001
|
||||
|
||||
Census Dictionary is available here https://www12.statcan.gc.ca/access_acces/archive.action-eng.cfm?/english/census01/products/reference/dict/appendices/92-378-XIE02002.pdf
|
||||
*/
|
||||
Executable
+290
@@ -0,0 +1,290 @@
|
||||
#!/bin/bash
|
||||
|
||||
import_to_postgis() {
|
||||
local filepath="$1"
|
||||
local table_name="$2"
|
||||
local extra_parameters="${@:3}"
|
||||
|
||||
# Handle zip files using GDAL's virtual file system
|
||||
if [[ "${filepath: -4}" == ".zip" ]]; then
|
||||
filepath="/vsizip/${filepath}"
|
||||
fi
|
||||
|
||||
echo "Importing ${filepath} into table ${table_name}"
|
||||
ogr2ogr \
|
||||
--config PG_USE_COPY YES \
|
||||
-lco "OVERWRITE=YES" \
|
||||
-f "PostgreSQL" \
|
||||
"PG:host=db dbname=${POSTGRES_DB} user=${POSTGRES_USER} password=${POSTGRES_PASSWORD} port=5432" \
|
||||
-lco GEOMETRY_NAME=geom \
|
||||
-progress \
|
||||
-gt 500000 \
|
||||
-t_srs EPSG:4326 \
|
||||
-nln "${table_name}" \
|
||||
${extra_parameters} \
|
||||
"${filepath}"
|
||||
}
|
||||
|
||||
# Define input folders
|
||||
INPUT_FOLDER="${DATA_FOLDER}/boundaries/input"
|
||||
EXTRACTED_FOLDER="${DATA_FOLDER}/boundaries/extracted"
|
||||
|
||||
import_data_2021() {
|
||||
# Source: https://web.archive.org/web/20230307163203/https://www12.statcan.gc.ca/census-recensement/2021/geo/sip-pis/boundary-limites/index2021-eng.cfm?year=21
|
||||
# Provinces/territories
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lpr_000a21a_e.zip" lpr_000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census divisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lcd_000a21a_e.zip" lcd_000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Federal electoral districts (2013 Representation Order)
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lfed000a21a_e.zip" lfed000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census subdivisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lcsd000a21a_e.zip" lcsd000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Designated places
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/ldpl000a21a_e.zip" ldpl000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Forward sortation areas
|
||||
unzip -n "${INPUT_FOLDER}/2021/lfsa000a21a_e.zip" -d "${EXTRACTED_FOLDER}/2021"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2021/lfsa000a21a_e/lfsa000a21a_e.shp" lfsa000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Economic regions
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/ler_000a21a_e.zip" ler_000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# There's issues with the Census agricultural regions encoding, statcan did not export the shapefile properly
|
||||
# Census agricultural regions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lcar000a21a_e.zip" lcar000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census consolidated subdivisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lccs000a21a_e.zip" lccs000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census metropolitan areas and census agglomerations
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lcma000a21a_e.zip" lcma000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census tracts
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lct_000a21a_e.zip" lct_000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Population centres
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lpc_000a21a_e.zip" lpc_000a21a_e "-lco SCHEMA=bronze"
|
||||
# Dissemination areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lda_000a21a_e.zip" lda_000a21a_e "-lco SCHEMA=bronze"
|
||||
# Dissemination blocks
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/ldb_000a21a_e.zip" ldb_000a21a_e "-lco SCHEMA=bronze"
|
||||
# Aggregate dissemination areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2021/lada000a21a_e.zip" lada000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Population ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2021/lecu000e21a_e.zip" -d "${EXTRACTED_FOLDER}/2021"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2021/lecu000e21a_e.shp" lecu000a21a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Agricultural ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2021/leca000e21a_e.zip" -d "${EXTRACTED_FOLDER}/2021"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2021/leca000e21a_e.shp" leca000e21a_e "-lco SCHEMA=bronze"
|
||||
}
|
||||
|
||||
import_data_2016() {
|
||||
# Source: https://web.archive.org/web/20230120140926/https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2016-eng.cfm
|
||||
# Provinces/territories
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lpr_000a16a_e.zip" lpr_000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Federal electoral districts (2013 Representation Order)
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lfed000a16a_e.zip" lfed000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Economic regions
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/ler_000a16a_e.zip" ler_000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census divisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lcd_000a16a_e.zip" lcd_000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Aggregate dissemination areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lada000a16a_e.zip" lada000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census agricultural regions
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lcar000a16a_e.zip" lcar000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census consolidated subdivisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lccs000a16a_e.zip" lccs000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census subdivisions
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lcsd000a16a_e.zip" lcsd000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census metropolitan areas and census agglomerations
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lcma000a16a_e.zip" lcma000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census tracts
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lct_000a16a_e.zip" lct_000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Dissemination areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lda_000a16a_e.zip" lda_000a16a_e "-lco SCHEMA=bronze"
|
||||
# Dissemination blocks
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/ldb_000a16a_e.zip" ldb_000a16a_e "-lco SCHEMA=bronze"
|
||||
# Designated places
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/ldpl000a16a_e.zip" ldpl000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Population centres
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lpc_000a16a_e.zip" lpc_000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Population ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2016/lecu000e16a_e.zip" -d "${EXTRACTED_FOLDER}/2016"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2016/lecu000e16a_e.shp" lecu000e16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Agricultural ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2016/geca000e16a_e.zip" -d ${EXTRACTED_FOLDER}/2016
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2016/lagecu000e16a_e.shp" lagecu000e16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Forward sortation areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2016/lfsa000a16a_e.zip" lfsa000a16a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
}
|
||||
|
||||
import_data_2011() {
|
||||
# Source: https://web.archive.org/web/20230110163150/https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2011-eng.cfm
|
||||
# Provinces/territories
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gpr_000a11a_e.zip" gpr_000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Federal electoral districts (2003 Representation Order)
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gfed000a11a_e.zip" gfed000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Economic regions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/ger_000a11a_e.zip" ger_000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census divisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gcd_000a11a_e.zip" gcd_000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census agricultural regions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gcar000a11a_e.zip" gcar000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census consolidated subdivisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gccs000a11a_e.zip" gccs000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census subdivisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gcsd000a11a_e.zip" gcsd000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census metropolitan areas and census agglomerations
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gcma000a11a_e.zip" gcma000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census tracts
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gct_000a11a_e.zip" gct_000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Dissemination areas
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gda_000a11a_e.zip" gda_000a11a_e "-lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Dissemination blocks
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gdb_000a11a_e.zip" gdb_000a11a_e "-lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Designated places
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gdpl000a11a_e.zip" gdpl000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Population centres
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gpc_000a11a_e.zip" gpc_000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Population ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2011/gecu000e11a_e.zip" -d "${EXTRACTED_FOLDER}/2011"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2011/gecu000e11a_e.shp" gecu000e11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Agricultural ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2011/geca000e11a_e.zip" -d "${EXTRACTED_FOLDER}/2011"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2011/geca000e11a_e.shp" geca000e11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Forward sortation areas
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2011/gfsa000a11a_e.zip" gfsa000a11a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
}
|
||||
|
||||
import_data_2006() {
|
||||
# Source: https://web.archive.org/web/20221218043125/https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2006-eng.cfm
|
||||
# Provinces/territories
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gpr_000a06a_e.zip" gpr_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Federal electoral districts (2003 Representation Order)
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gfed000a06a_e.zip" gfed000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Economic regions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/ger_000a06a_e.zip" ger_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census divisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gcd_000a06a_e.zip" gcd_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census agricultural regions
|
||||
#import_to_postgis "${INPUT_FOLDER}/2006/gcar000a06a_e.zip" gcar000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census consolidated subdivisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gccs000a06a_e.zip" gccs000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census subdivisions
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gcsd000a06a_e.zip" gcsd000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census metropolitan areas and census agglomerations
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gcma000a06a_e.zip" gcma000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Census tracts
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gct_000a06a_e.zip" gct_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Dissemination areas
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gda_000a06a_e.zip" gda_000a06a_e "-lco SCHEMA=bronze"
|
||||
# Dissemination blocks
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gdb_000a06a_e.zip" gdb_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Designated places
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gdpl000a06a_e.zip" gdpl000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Urban areas
|
||||
export PGCLIENTENCODING=LATIN-1;
|
||||
import_to_postgis "${INPUT_FOLDER}/2006/gua_000a06a_e.zip" gua_000a06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
unset PGCLIENTENCODING
|
||||
# Population ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2006/gecu000e06a_e.zip" -d "${EXTRACTED_FOLDER}/2006"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2006/gecu000e06a_e.shp" gecu000e06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Agricultural ecumene
|
||||
unzip -o "${INPUT_FOLDER}/2006/geca000e06a_e.zip" -d ${EXTRACTED_FOLDER}/2006
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2006/geca000e06a_e.shp" geca000e06a_e "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
}
|
||||
|
||||
import_data_2001() {
|
||||
# Source: https://web.archive.org/web/20221218043135/https://www12.statcan.gc.ca/census-recensement/2011/geo/bound-limit/bound-limit-2001-eng.cfm
|
||||
# TODO: merge geometries by unique identifier for all but the block
|
||||
# Provinces/Territories
|
||||
unzip -n "${INPUT_FOLDER}/2001/gpr_000b01m_e.zip" -d ${EXTRACTED_FOLDER}/2001
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gpr_000b02m_e/gpr_000b02m_e.MID" gpr_000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Federal Electoral Districts (1996 and 2003 Representation Orders)
|
||||
unzip -n "${INPUT_FOLDER}/2001/gfed000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gfed000b02m_e/gfed000b02m_e.MID" gfed000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Economic Regions
|
||||
unzip -n "${INPUT_FOLDER}/2001/ger_000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/ger_000b02m_e/ger_000b02m_e.MID" ger_000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Divisions
|
||||
unzip -n "${INPUT_FOLDER}/2001/gcd_000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gcd_000b02m_e/gcd_000b02m_e.MID" gcd_000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Agricultural Regions
|
||||
unzip -n "${INPUT_FOLDER}/2001/gcar000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gcar000b03m_e/gcar000b03m_e.mid" gcar000b03m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Consolidated Subdivisions
|
||||
unzip -n "${INPUT_FOLDER}/2001/gccs000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gccs000b02m_e/gccs000b02m_e.MID" gccs000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Subdivisions
|
||||
unzip -n "${INPUT_FOLDER}/2001/gcsd000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gcsd000b02m_e/gcsd000b02m_e.MID" gcsd000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Metropolitan Areas and Census Agglomerations
|
||||
unzip -n "${INPUT_FOLDER}/2001/gcma000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gcma000b02m_e/gcma000b02m_e.MID" gcma000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Census Tracts
|
||||
unzip -n "${INPUT_FOLDER}/2001/gct_000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gct_000b02m_e/gct_000b02m_e.MID" gct_000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Dissemination Areas
|
||||
unzip -n "${INPUT_FOLDER}/2001/gda_000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gda_000b02m_e/gda_000b02m_e.MID" gda_000b02m_e_tmp "-lco SCHEMA=bronze"
|
||||
# Blocks (no need to merge geometries)
|
||||
unzip -n "${INPUT_FOLDER}/2001/gdb_000a01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gbl_000d02m_e/gbl_000d02m_e.TAB" gbl_000d02m_e_tmp "-lco SCHEMA=bronze"
|
||||
# Designated Places
|
||||
unzip -n "${INPUT_FOLDER}/2001/gdpl000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gdpl000b02m_e/gdpl000b02m_e.MID" gdpl000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# Urban Areas
|
||||
unzip -n "${INPUT_FOLDER}/2001/gua_000b01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/gua_000b02m_e/gua_000b02m_e.MID" gua000b02m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
# TODO
|
||||
# Population Ecumene
|
||||
# Agricultural Ecumene
|
||||
unzip -n "${INPUT_FOLDER}/2001/geca000e01m_e.zip" -d "${EXTRACTED_FOLDER}/2001"
|
||||
import_to_postgis "${EXTRACTED_FOLDER}/2001/geca000e03m_e/geca000e03m_e.mid" geca000e03m_e_tmp "-nlt PROMOTE_TO_MULTI -lco SCHEMA=bronze"
|
||||
}
|
||||
|
||||
# Execute all import functions
|
||||
import_data_2021
|
||||
import_data_2016
|
||||
import_data_2011
|
||||
import_data_2006
|
||||
#import_data_2001
|
||||
@@ -0,0 +1,608 @@
|
||||
/*
|
||||
PR
|
||||
*/
|
||||
|
||||
/* 2001 Provinces and Territories */
|
||||
drop table if exists statcan_pr_2001;
|
||||
create table statcan_pr_2001 as
|
||||
select distinct pruid, prename, prfname, preabbr, prfabbr,
|
||||
concat('2001A0002', pruid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gpr_000b02m_e_tmp
|
||||
group by pruid, prename, prfname, preabbr, prfabbr;
|
||||
|
||||
create index statcan_pr_2001_geom_idx on statcan_pr_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gpr_000b02m_e_tmp;
|
||||
|
||||
/* 2006 Provinces and Territories */
|
||||
drop table if exists statcan_pr_2006;
|
||||
create table statcan_pr_2006 as
|
||||
select pruid, prename, prfname, preabbr, prfabbr,
|
||||
concat('2006A0002', pruid) as dguid,
|
||||
geom
|
||||
from statcan_gpr_000a06a_e;
|
||||
|
||||
create index statcan_pr_2006_geom_idx on statcan_pr_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gpr_000b02m_e_tmp;
|
||||
|
||||
/* 2011 Provinces and Territories */
|
||||
drop table if exists statcan_pr_2011;
|
||||
create table statcan_pr_2011 as
|
||||
select pruid, prename, prfname, preabbr, prfabbr,
|
||||
concat('2011A0002', pruid) as dguid,
|
||||
geom
|
||||
from statcan_gpr_000a11a_e;
|
||||
|
||||
create index statcan_pr_2011_geom_idx on statcan_pr_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gpr_000a11a_e;
|
||||
|
||||
/* 2016 Provinces and Territories */
|
||||
drop table if exists statcan_pr_2016;
|
||||
create table statcan_pr_2016 as
|
||||
select pruid, prename, prfname, preabbr, prfabbr,
|
||||
concat('2016A0002', pruid) as dguid,
|
||||
geom
|
||||
from statcan_lpr_000a16a_e;
|
||||
|
||||
create index statcan_pr_2016_geom_idx on statcan_pr_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lpr_000a16a_e;
|
||||
|
||||
/*
|
||||
CD
|
||||
*/
|
||||
--- 2001 Census Divisions;
|
||||
drop table if exists statcan_cd_2001;
|
||||
create table statcan_cd_2001 as
|
||||
select distinct pruid, cduid, cdname, cdtype,
|
||||
concat('2001A0003', cduid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gcd_000b02m_e_tmp
|
||||
group by pruid, cduid, cdname, cdtype;
|
||||
|
||||
create index statcan_cd_2001_geom_idx on statcan_cd_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcd_000b02m_e_tmp;
|
||||
|
||||
--- 2006 Census Divisions;
|
||||
drop table if exists statcan_cd_2006;
|
||||
create table statcan_cd_2006 as
|
||||
select pruid, cduid, cdname, cdtype,
|
||||
concat('2006A0003', cduid) as dguid,
|
||||
geom
|
||||
from statcan_gcd_000a06a_e;
|
||||
|
||||
create index statcan_cd_2006_geom_idx on statcan_cd_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcd_000a06a_e;
|
||||
|
||||
--- 2011 Census Divisions;
|
||||
drop table if exists statcan_cd_2011;
|
||||
create table statcan_cd_2011 as
|
||||
select pruid, cduid, cdname, cdtype, concat('2011A0003', cduid) as dguid,
|
||||
geom
|
||||
from statcan_gcd_000a11a_e;
|
||||
|
||||
create index statcan_cd_2011_geom_idx on statcan_cd_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcd_000a11a_e;
|
||||
|
||||
--- 2016 Census Divisions;
|
||||
drop table if exists statcan_cd_2016;
|
||||
create table statcan_cd_2016 as
|
||||
select pruid, cduid, cdname, cdtype,
|
||||
concat('2016A0003', cduid) as dguid,
|
||||
geom
|
||||
from statcan_lcd_000a16a_e;
|
||||
|
||||
create index statcan_cd_2016_geom_idx on statcan_cd_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lcd_000a16a_e;
|
||||
|
||||
/*
|
||||
ER
|
||||
*/
|
||||
--- 2001 Economic Regions;
|
||||
drop table if exists statcan_er_2001;
|
||||
create table statcan_er_2001 as
|
||||
select distinct pruid, eruid, ername,
|
||||
concat('2001S0500', eruid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_ger_000b02m_e_tmp
|
||||
group by pruid, eruid, ername;
|
||||
|
||||
create index statcan_er_2001_geom_idx on statcan_er_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ger_000b02m_e_tmp;
|
||||
|
||||
--- 2006 Economic Regions;
|
||||
drop table if exists statcan_er_2006;
|
||||
create table statcan_er_2006 as
|
||||
select distinct pruid, eruid, ername,
|
||||
concat('2006S0500', eruid) as dguid, geom
|
||||
from statcan_ger_000a06a_e;
|
||||
|
||||
create index statcan_er_2006_geom_idx on statcan_er_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ger_000a06a_e;
|
||||
|
||||
--- 2011 Economic Regions;
|
||||
drop table if exists statcan_er_2011;
|
||||
create table statcan_er_2011 as
|
||||
select distinct pruid, eruid, ername,
|
||||
concat('2011S0500', eruid) as dguid, geom
|
||||
from statcan_ger_000a11a_e;
|
||||
|
||||
create index statcan_er_2011_geom_idx on statcan_er_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ger_000a11a_e;
|
||||
|
||||
--- 2016 Economic Regions;
|
||||
drop table if exists statcan_er_2016;
|
||||
create table statcan_er_2016 as
|
||||
select distinct pruid, eruid, ername,
|
||||
concat('2016S0500', eruid) as dguid, geom
|
||||
from statcan_ler_000a16a_e;
|
||||
|
||||
create index statcan_er_2016_geom_idx on statcan_er_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ler_000a16a_e;
|
||||
|
||||
/*
|
||||
CCS
|
||||
*/
|
||||
|
||||
--- 2001 Census Consolidated Subdivision;
|
||||
drop table if exists statcan_ccs_2001;
|
||||
create table statcan_ccs_2001 as
|
||||
select distinct pruid, ccsuid, ccsname,
|
||||
concat('2001S0502', ccsuid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gccs000b02m_e_tmp
|
||||
group by pruid, ccsuid, ccsname;
|
||||
|
||||
create index statcan_ccs_2001_geom_idx on statcan_ccs_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gccs000b02m_e_tmp;
|
||||
|
||||
--- 2006 Census Consolidated Subdivision;
|
||||
drop table if exists statcan_ccs_2006;
|
||||
create table statcan_ccs_2006 as
|
||||
select distinct pruid, ccsuid, ccsname,
|
||||
concat('2006S0502', ccsuid) as dguid, geom
|
||||
from statcan_gccs000a06a_e;
|
||||
|
||||
create index statcan_ccs_2006_geom_idx on statcan_ccs_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gccs000a06a_e;
|
||||
|
||||
--- 2011 Census Consolidated Subdivision;
|
||||
drop table if exists statcan_ccs_2011;
|
||||
create table statcan_ccs_2011 as
|
||||
select distinct pruid, cduid, ccsuid, ccsname,
|
||||
concat('2011S0502', ccsuid) as dguid, geom
|
||||
from statcan_gccs000a11a_e;
|
||||
|
||||
create index statcan_ccs_2011_geom_idx on statcan_ccs_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gccs000a11a_e;
|
||||
|
||||
--- 2016 Census Consolidated Subdivision;
|
||||
drop table if exists statcan_ccs_2016;
|
||||
create table statcan_ccs_2016 as
|
||||
select distinct pruid, cduid, ccsuid, ccsname,
|
||||
concat('2016S0502', ccsuid) as dguid, geom
|
||||
from statcan_lcsd000a16a_e;
|
||||
|
||||
create index statcan_ccs_2016_geom_idx on statcan_ccs_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lcsd000a16a_e;
|
||||
|
||||
/*
|
||||
CSD
|
||||
*/
|
||||
|
||||
/* 2001 Census Subdivisions */
|
||||
drop table if exists statcan_csd_2001;
|
||||
create table statcan_csd_2001 as
|
||||
select distinct pruid, csduid, csdname, csdtype, eruid,
|
||||
concat('2001A0005', csduid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gcsd000b02m_e_tmp
|
||||
group by pruid, csduid, csdname, csdtype, eruid;
|
||||
|
||||
create index statcan_csd_2001_geom_idx on statcan_csd_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcsd000b02m_e_tmp;
|
||||
|
||||
/* 2006 Census Subdivisions */
|
||||
drop table if exists statcan_csd_2006;
|
||||
create table statcan_csd_2006 as
|
||||
select pruid, csduid, csdname, csdtype, concat(pruid, cmauid) as cmapuid,
|
||||
concat('2006A0005', csduid) as dguid,
|
||||
geom
|
||||
from statcan_gcsd000a06a_e;
|
||||
|
||||
create index statcan_csd_2006_geom_idx on statcan_csd_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcsd000a06a_e;
|
||||
|
||||
/* 2011 Census Subdivisions */
|
||||
drop table if exists statcan_csd_2011;
|
||||
create table statcan_csd_2011 as
|
||||
select pruid, cduid, ccsuid, csduid, csdname, csdtype, eruid, cmapuid,
|
||||
concat('2011A0005', csduid) as dguid,
|
||||
geom
|
||||
from statcan_gcsd000a11a_e;
|
||||
|
||||
create index statcan_csd_2011_geom_idx on statcan_csd_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcsd000a11a_e;
|
||||
|
||||
/* 2016 Census Subdivisions */
|
||||
drop table if exists statcan_csd_2016;
|
||||
create table statcan_csd_2016 as
|
||||
select pruid, cduid, ccsuid, csduid, csdname, csdtype, eruid, cmapuid,
|
||||
concat('2016A0005', csduid) as dguid,
|
||||
geom
|
||||
from statcan_lcsd000a16a_e;
|
||||
|
||||
create index statcan_csd_2016_geom_idx on statcan_csd_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lcsd000a16a_e;
|
||||
|
||||
/*
|
||||
FED
|
||||
*/
|
||||
|
||||
--- 2003 Federal Electoral Districts;
|
||||
drop table if exists statcan_fed_2003;
|
||||
create table statcan_fed_2003 as
|
||||
select distinct pruid, feduid, fedname, fedename, fedfname,
|
||||
concat('2003A0004', feduid) as dguid, geom
|
||||
from statcan_gfed000a11a_e;
|
||||
|
||||
create index statcan_fed_2003_geom_idx on statcan_fed_2003 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gfed000a11a_e;
|
||||
|
||||
--- 2013 Federal Electoral Districts;
|
||||
drop table if exists statcan_fed_2013;
|
||||
create table statcan_fed_2013 as
|
||||
select distinct pruid, feduid, fedname, fedename, fedfname,
|
||||
concat('2013A0004', feduid) as dguid, geom
|
||||
from statcan_lfed000a21a_e;
|
||||
|
||||
create index statcan_fed_2013_geom_idx on statcan_fed_2013 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lfed000a21a_e;
|
||||
drop table if exists statcan_lfed000a16a_e;
|
||||
|
||||
/*
|
||||
Census Agricultural Regions
|
||||
*/
|
||||
|
||||
--- 2001 Census Agricultural Regions;
|
||||
drop table if exists statcan_car_2001;
|
||||
create table statcan_car_2001 as
|
||||
select distinct pruid, caruid, carname, aguid, water,
|
||||
concat('2001S0501', caruid) as dguid, geom
|
||||
from statcan_gcar000b03m_e_tmp;
|
||||
|
||||
create index statcan_car_2001_geom_idx on statcan_car_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcar000b03m_e_tmp;
|
||||
|
||||
--- 2006 Census Agricultural Regions;
|
||||
drop table if exists statcan_car_2006;
|
||||
create table statcan_car_2006 as
|
||||
select distinct pruid, caruid, carname, aguid,
|
||||
concat('2006S0501', caruid) as dguid, geom
|
||||
from statcan_gcar000a06a_e;
|
||||
|
||||
create index statcan_car_2006_geom_idx on statcan_car_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcar000a06a_e;
|
||||
|
||||
--- 2011 Census Agricultural Regions;
|
||||
drop table if exists statcan_car_2011;
|
||||
create table statcan_car_2011 as
|
||||
select distinct pruid, caruid, carname, aguid,
|
||||
concat('2011S0501', caruid) as dguid, geom
|
||||
from statcan_gcar000a11a_e;
|
||||
|
||||
create index statcan_car_2011_geom_idx on statcan_car_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcar000a11a_e;
|
||||
|
||||
--- 2016 Census Agricultural Regions;
|
||||
drop table if exists statcan_car_2016;
|
||||
create table statcan_car_2016 as
|
||||
select distinct pruid, caruid, carename, carfname,
|
||||
concat('2016S0501', caruid) as dguid, geom
|
||||
from statcan_lcar000a16a_e;
|
||||
|
||||
create index statcan_car_2016_geom_idx on statcan_car_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lcar000a16a_e;
|
||||
|
||||
/*
|
||||
Designated Places
|
||||
*/
|
||||
|
||||
--- 2001 Designated Places;
|
||||
drop table if exists statcan_dpl_2001;
|
||||
create table statcan_dpl_2001 as
|
||||
select distinct pruid, dpluid, dplname, dpltype,
|
||||
concat('2001A0006', dpluid) as dguid,
|
||||
st_union(st_makevalid(geom)) as geom
|
||||
from statcan_gdpl000b02m_e_tmp
|
||||
group by pruid, dpluid, dplname, dpltype;
|
||||
|
||||
create index statcan_dpl_2001_geom_idx on statcan_dpl_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gdpl000b02m_e_tmp;
|
||||
|
||||
--- 2006 Designated Places;
|
||||
drop table if exists statcan_dpl_2006;
|
||||
create table statcan_dpl_2006 as
|
||||
select distinct pruid, csduid, dpluid, dplname, dpltype,
|
||||
concat('2006A0006', dpluid) as dguid, geom
|
||||
from statcan_gdpl000a06a_e;
|
||||
|
||||
create index statcan_dpl_2006_geom_idx on statcan_dpl_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gdpl000a06a_e;
|
||||
|
||||
--- 2011 Designated Places;
|
||||
drop table if exists statcan_dpl_2011;
|
||||
create table statcan_dpl_2011 as
|
||||
select distinct pruid, dpluid, dplname, dpltype,
|
||||
concat('2011A0006', dpluid) as dguid, geom
|
||||
from statcan_gdpl000a11a_e;
|
||||
|
||||
create index statcan_dpl_2011_geom_idx on statcan_dpl_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gdpl000a11a_e;
|
||||
|
||||
--- 2016 Designated Places;
|
||||
drop table if exists statcan_dpl_2016;
|
||||
create table statcan_dpl_2016 as
|
||||
select distinct pruid, dpluid, dplname, dpltype,
|
||||
concat('2016A0006', dpluid) as dguid, geom
|
||||
from statcan_ldpl000a16a_e;
|
||||
|
||||
create index statcan_dpl_2016_geom_idx on statcan_dpl_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ldpl000a16a_e;
|
||||
|
||||
/*
|
||||
FSA
|
||||
*/
|
||||
|
||||
--- 2011 FSA;
|
||||
drop table if exists statcan_fsa_2011;
|
||||
create table statcan_fsa_2011 as
|
||||
select distinct pruid, cfsauid, concat('2011A0011', cfsauid) as dguid, geom
|
||||
from statcan_gfsa000a11a_e;
|
||||
|
||||
create index statcan_fsa_2011_geom_idx on statcan_fsa_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gfsa000a11a_e;
|
||||
|
||||
--- 2016 FSA;
|
||||
drop table if exists statcan_fsa_2016;
|
||||
create table statcan_fsa_2016 as
|
||||
select distinct pruid, cfsauid, concat('2016A0011', cfsauid) as dguid, geom
|
||||
from statcan_lfsa000a16a_e;
|
||||
|
||||
create index statcan_fsa_2016_geom_idx on statcan_fsa_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lfsa000a16a_e;
|
||||
|
||||
/*
|
||||
CMA
|
||||
*/
|
||||
|
||||
--- 2001 CMA;
|
||||
drop table if exists statcan_cma_2001;
|
||||
create table statcan_cma_2001 as
|
||||
select distinct cmauid, concat(pruid, cmauid) as cmapuid, cmaname, cmatype, pruid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gcma000b02m_e_tmp
|
||||
group by cmaname, cmauid, cmatype, pruid;
|
||||
|
||||
create index statcan_cma_2001_geom_idx on statcan_cma_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcma000b02m_e_tmp;
|
||||
|
||||
--- 2006 CMA;
|
||||
drop table if exists statcan_cma_2006;
|
||||
create table statcan_cma_2006 as
|
||||
select cmauid as cmapuid, cmaname, cmatype, pruid, geom
|
||||
from statcan_gcma000a06a_e;
|
||||
|
||||
create index statcan_cma_2006_geom_idx on statcan_cma_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcma000a06a_e;
|
||||
|
||||
--- 2011 CMA;
|
||||
drop table if exists statcan_cma_2011;
|
||||
create table statcan_cma_2011 as
|
||||
select cmauid, cmapuid, cmaname, cmatype, pruid, geom
|
||||
from statcan_gcma000a11a_e;
|
||||
|
||||
create index statcan_cma_2011_geom_idx on statcan_cma_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gcma000a11a_e;
|
||||
|
||||
--- 2016 CMA;
|
||||
drop table if exists statcan_cma_2016;
|
||||
create table statcan_cma_2016 as
|
||||
select cmauid, cmapuid, cmaname, cmatype, pruid, geom
|
||||
from statcan_lcma000a16a_e;
|
||||
|
||||
create index statcan_cma_2016_geom_idx on statcan_cma_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lcma000a16a_e;
|
||||
|
||||
/*
|
||||
Population Centres
|
||||
*/
|
||||
|
||||
--- 2011 Population Centres;
|
||||
drop table if exists statcan_pc_2011;
|
||||
create table statcan_pc_2011 as
|
||||
select distinct pruid, cmapuid, pcuid, pcpuid, pcname, pctype,
|
||||
concat('2011S0510', pcuid) as dguid, geom
|
||||
from statcan_gpc_000a11a_e;
|
||||
|
||||
create index statcan_pc_2011_geom_idx on statcan_pc_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
|
||||
--- 2016 Population Centres;
|
||||
drop table if exists statcan_pc_2016;
|
||||
create table statcan_pc_2016 as
|
||||
select distinct pruid, cmapuid, pcuid, pcpuid, pcname, pctype,
|
||||
concat('2016S0510', pcuid) as dguid, geom
|
||||
from statcan_lpc_000a16a_e;
|
||||
|
||||
create index statcan_pc_2016_geom_idx on statcan_pc_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
|
||||
/*
|
||||
Population Centres Part
|
||||
*/
|
||||
|
||||
--- 2011 Population Centres Part;
|
||||
drop table if exists statcan_pc_part_2011;
|
||||
create table statcan_pc_part_2011 as
|
||||
select distinct pruid, cmapuid, pcuid, pcpuid, pcname, pctype,
|
||||
concat('2011S0511', pcpuid) as dguid, geom
|
||||
from statcan_gpc_000a11a_e;
|
||||
|
||||
create index statcan_pc_part_2011_geom_idx on statcan_pc_part_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gpc_000a11a_e;
|
||||
|
||||
--- 2016 Population Centres Part;
|
||||
drop table if exists statcan_pc_part_2016;
|
||||
create table statcan_pc_part_2016 as
|
||||
select distinct pruid, cmapuid, pcuid, pcpuid, pcname, pctype,
|
||||
concat('2016S0511', pcpuid) as dguid, geom
|
||||
from statcan_lpc_000a16a_e;
|
||||
|
||||
create index statcan_pc_part_2016_geom_idx on statcan_pc_part_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lpc_000a16a_e;
|
||||
|
||||
/*
|
||||
Census Tracts
|
||||
*/
|
||||
--- 2001 Census Tracts;
|
||||
drop table if exists statcan_ct_2001;
|
||||
create table statcan_ct_2001 as
|
||||
select distinct pruid, ctuid, ctname, concat(pruid, cmauid) as cmapuid,
|
||||
concat('2001S0507', ctuid) as dguid, st_union(geom) as geom
|
||||
from statcan_gct_000b02m_e_tmp
|
||||
group by pruid, ctuid, ctname, cmauid;
|
||||
|
||||
create index statcan_ct_2001_geom_idx on statcan_ct_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gct_000b02m_e_tmp;
|
||||
|
||||
--- 2006 Census Tracts;
|
||||
drop table if exists statcan_ct_2006;
|
||||
create table statcan_ct_2006 as
|
||||
select distinct pruid, ctuid, concat(pruid, cmauid) as cmapuid,
|
||||
concat('2006S0507', ctuid) as dguid, geom
|
||||
from statcan_gct_000a06a_e;
|
||||
|
||||
create index statcan_ct_2006_geom_idx on statcan_ct_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gct_000a06a_e;
|
||||
|
||||
--- 2011 Census Tracts;
|
||||
drop table if exists statcan_ct_2011;
|
||||
create table statcan_ct_2011 as
|
||||
select distinct pruid, ctuid, ctname, cmapuid,
|
||||
concat('2011S0507', ctuid) as dguid, geom
|
||||
from statcan_gct_000a11a_e;
|
||||
|
||||
create index statcan_ct_2011_geom_idx on statcan_ct_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gct_000a11a_e;
|
||||
|
||||
--- 2016 Census Tracts;
|
||||
drop table if exists statcan_ct_2016;
|
||||
create table statcan_ct_2016 as
|
||||
select distinct pruid, ctuid, ctname, cmapuid,
|
||||
concat('2016S0507', ctuid) as dguid, geom
|
||||
from statcan_lct_000a16a_e;
|
||||
|
||||
create index statcan_ct_2016_geom_idx on statcan_ct_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lct_000a16a_e;
|
||||
|
||||
/*
|
||||
DA
|
||||
*/
|
||||
--- 2001 Dissemination Areas;
|
||||
drop table if exists statcan_da_2001;
|
||||
create table statcan_da_2001 as
|
||||
select distinct pruid, csduid, concat(pruid, cmauid) as cmapuid, dauid,
|
||||
concat('2001S0512', dauid) as dguid,
|
||||
st_union(geom) as geom
|
||||
from statcan_gda_000b02m_e_tmp
|
||||
group by pruid, csduid, cmauid, dauid;
|
||||
|
||||
create index statcan_da_2001_geom_idx on statcan_da_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gda_000b02m_e_tmp;
|
||||
|
||||
--- 2006 Dissemination Area;
|
||||
drop table if exists statcan_da_2006;
|
||||
create table statcan_da_2006 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, concat(pruid, cmauid) as cmapuid, ctuid, dauid,
|
||||
concat('2006S0512', dauid) as dguid, geom
|
||||
from statcan_gda_000a06a_e;
|
||||
|
||||
create index statcan_da_2006_geom_idx on statcan_da_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gda_000a06a_e;
|
||||
|
||||
--- 2011 Dissemination Area;
|
||||
drop table if exists statcan_da_2011;
|
||||
create table statcan_da_2011 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, cmapuid, ctuid, dauid,
|
||||
concat('2011S0512', dauid) as dguid, geom
|
||||
from statcan_gda_000a11a_e;
|
||||
|
||||
create index statcan_da_2011_geom_idx on statcan_da_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gda_000a11a_e;
|
||||
|
||||
--- 2016 Dissemination Area;
|
||||
drop table if exists statcan_da_2016;
|
||||
create table statcan_da_2016 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, cmapuid, ctuid, adauid, dauid,
|
||||
concat('2016S0512', dauid) as dguid, geom
|
||||
from statcan_lda_000a16a_e;
|
||||
|
||||
create index statcan_da_2016_geom_idx on statcan_da_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lda_000a16a_e;
|
||||
|
||||
/*
|
||||
DB
|
||||
*/
|
||||
|
||||
--- 2001 Dissemination Blocks;
|
||||
drop table if exists statcan_db_2001;
|
||||
create table statcan_db_2001 as
|
||||
select distinct pruid, csduid, concat(pruid, cmauid) as cmapuid, ctname, dauid, blockuid as dbuid,
|
||||
concat('2001S0513', blockuid) as dguid, geom
|
||||
from statcan_gbl_000d02m_e_tmp;
|
||||
|
||||
create index statcan_db_2001_geom_idx on statcan_db_2001 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gbl_000d02m_e_tmp;
|
||||
|
||||
--- 2006 Dissemination Blocks;
|
||||
drop table if exists statcan_db_2006;
|
||||
create table statcan_db_2006 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, concat(pruid, cmauid) as cmapuid, ctuid, dauid, dbuid,
|
||||
concat('2006S0513', dbuid) as dguid, geom
|
||||
from statcan_gdb_000a06a_e;
|
||||
|
||||
create index statcan_db_2006_geom_idx on statcan_db_2006 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gdb_000a06a_e;
|
||||
|
||||
--- 2011 Dissemination Blocks;
|
||||
drop table if exists statcan_db_2011;
|
||||
create table statcan_db_2011 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, feduid,
|
||||
concat(pruid, cmauid) as cmapuid, ctuid, dauid, dbuid,
|
||||
concat('2011S0513', dbuid) as dguid, geom
|
||||
from statcan_gdb_000a11a_e;
|
||||
|
||||
create index statcan_db_2011_geom_idx on statcan_db_2011 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_gdb_000a11a_e;
|
||||
|
||||
--- 2016 Dissemination Blocks;
|
||||
drop table if exists statcan_db_2016;
|
||||
create table statcan_db_2016 as
|
||||
select distinct pruid, cduid, ccsuid, csduid, eruid, feduid, cmapuid, ctuid, adauid, dauid, dbuid,
|
||||
concat('2016S0513', dbuid) as dguid, geom
|
||||
from statcan_ldb_000a16a_e;
|
||||
|
||||
create index statcan_db_2016_geom_idx on statcan_db_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_ldb_000a16a_e;
|
||||
|
||||
/*
|
||||
ADA
|
||||
*/
|
||||
|
||||
-- 2016 Aggregate Dissemination Areas;
|
||||
drop table if exists statcan_ada_2016;
|
||||
create table statcan_ada_2016 as
|
||||
select distinct pruid, cduid, adauid,
|
||||
concat('2016S0516', adauid) as dguid, geom
|
||||
from statcan_lada000a16a_e;
|
||||
|
||||
create index statcan_ada_2016_geom_idx on statcan_ada_2016 using GIST(geom) with (FILLFACTOR=100);
|
||||
drop table if exists statcan_lada000a16a_e;
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
Population Centres
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20250324222733/https://www12.statcan.gc.ca/census-recensement/2021/ref/dict/az/definition-eng.cfm?ID=geo049a
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.pop_ctr_2021;
|
||||
CREATE TABLE silver.pop_ctr_2021 AS
|
||||
SELECT DISTINCT
|
||||
pr.country_dguid,
|
||||
pr.country_en_name,
|
||||
pr.country_fr_name,
|
||||
pr.country_en_abbreviation,
|
||||
pr.country_fr_abbreviation,
|
||||
pr.grc_dguid,
|
||||
pr.grc_en_name,
|
||||
pr.grc_fr_name,
|
||||
pr.pr_dguid,
|
||||
pr.pr_en_name,
|
||||
pr.pr_fr_name,
|
||||
pr.pr_en_abbreviation,
|
||||
pr.pr_fr_abbreviation,
|
||||
pr.pr_iso_code,
|
||||
gaf.pop_ctr_dguid,
|
||||
gaf.pop_ctr_p_dguid,
|
||||
pop_ctr.pcname AS pop_ctr_name,
|
||||
pop_ctr.pctype AS pop_ctr_type,
|
||||
pop_ctr.pcclass AS pop_ctr_class,
|
||||
pop_ctr.geom
|
||||
FROM silver.gaf_2021 AS gaf
|
||||
LEFT JOIN bronze.lpc_000a21a_e AS pop_ctr
|
||||
ON
|
||||
concat(gaf.pop_ctr_dguid, gaf.pop_ctr_p_dguid)
|
||||
= concat(pop_ctr.dguid, pop_ctr.dguidp)
|
||||
LEFT JOIN silver.pr_2021 AS pr
|
||||
ON gaf.pr_dguid = pr.pr_dguid
|
||||
WHERE gaf.pop_ctr_dguid IS NOT null OR gaf.pop_ctr_p_dguid IS NOT null;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.pop_ctr_2021
|
||||
SET
|
||||
geom = st_makevalid(geom)
|
||||
WHERE
|
||||
st_isvalid(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX pop_ctr_2021_geom_idx ON silver.pop_ctr_2021 USING gist (
|
||||
geom
|
||||
) WITH (fillfactor = 100);
|
||||
Executable
+18
@@ -0,0 +1,18 @@
|
||||
# Standardizes field names, builds up hierarchy for datasets, create Canada and Geographic Regions of Canada
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/country.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/geographic_regions_of_canada.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/provinces_and_territories.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_divisions.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/economic_regions.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_agricultural_regions.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/forward_sortation_areas.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/federal_electoral_districts.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_consolidated_subdivisions.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_metropolitan_areas.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_subdivisions.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/population_centres.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/designated_places.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/census_tracts.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/aggregate_dissemination_areas.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/dissemination_areas.sql
|
||||
psql "postgresql://$POSTGRES_USER:$POSTGRES_PASSWORD@db/$POSTGRES_DB" -f boundaries/dissemination_blocks.sql
|
||||
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
Provinces and territories
|
||||
*/
|
||||
|
||||
/* 2021
|
||||
Definition here: https://web.archive.org/web/20240402175445/https://www150.statcan.gc.ca/n1/pub/92-195-x/2021001/geo/prov/prov-eng.htm
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.pr_2021;
|
||||
CREATE TABLE silver.pr_2021 AS
|
||||
SELECT DISTINCT
|
||||
grc.country_dguid,
|
||||
grc.country_en_name,
|
||||
grc.country_fr_name,
|
||||
grc.country_en_abbreviation,
|
||||
grc.country_fr_abbreviation,
|
||||
grc.grc_dguid,
|
||||
grc.grc_en_name,
|
||||
grc.grc_fr_name,
|
||||
pr.dguid AS pr_dguid,
|
||||
pr.prename AS pr_en_name,
|
||||
pr.prfname AS pr_fr_name,
|
||||
pr.preabbr AS pr_en_abbreviation,
|
||||
pr.prfabbr AS pr_fr_abbreviation,
|
||||
CASE
|
||||
WHEN pr.pruid = '10' THEN 'NL'
|
||||
WHEN pr.pruid = '11' THEN 'PE'
|
||||
WHEN pr.pruid = '12' THEN 'NS'
|
||||
WHEN pr.pruid = '13' THEN 'NB'
|
||||
WHEN pr.pruid = '24' THEN 'QC'
|
||||
WHEN pr.pruid = '35' THEN 'ON'
|
||||
WHEN pr.pruid = '46' THEN 'MB'
|
||||
WHEN pr.pruid = '47' THEN 'SK'
|
||||
WHEN pr.pruid = '48' THEN 'AB'
|
||||
WHEN pr.pruid = '59' THEN 'BC'
|
||||
WHEN pr.pruid = '60' THEN 'YT'
|
||||
WHEN pr.pruid = '61' THEN 'NT'
|
||||
WHEN pr.pruid = '62' THEN 'NU'
|
||||
END AS pr_iso_code,
|
||||
pr.geom
|
||||
FROM
|
||||
bronze.lpr_000a21a_e AS pr,
|
||||
silver.grc_pr_2021 AS grc
|
||||
WHERE
|
||||
grc.pr_dguid = pr.dguid;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.pr_2021
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX pr_2021_geom_idx ON pr_2021 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
|
||||
/* 2016
|
||||
Definition here: https://web.archive.org/web/20241104061057/https://www12.statcan.gc.ca/census-recensement/2016/ref/dict/geo038-eng.cfm
|
||||
*/
|
||||
|
||||
DROP TABLE IF EXISTS silver.pr_2016;
|
||||
CREATE TABLE silver.pr_2016 AS
|
||||
SELECT DISTINCT
|
||||
grc.country_dguid,
|
||||
grc.country_en_name,
|
||||
grc.country_fr_name,
|
||||
grc.country_en_abbreviation,
|
||||
grc.country_fr_abbreviation,
|
||||
grc.grc_dguid,
|
||||
grc.grc_en_name,
|
||||
grc.grc_fr_name,
|
||||
CONCAT('2016A0002', pr.pruid) AS pr_dguid,
|
||||
pr.prename AS pr_en_name,
|
||||
pr.prfname AS pr_fr_name,
|
||||
pr.preabbr AS pr_en_abbreviation,
|
||||
pr.prfabbr AS pr_fr_abbreviation,
|
||||
CASE
|
||||
WHEN pr.pruid = '10' THEN 'NL'
|
||||
WHEN pr.pruid = '11' THEN 'PE'
|
||||
WHEN pr.pruid = '12' THEN 'NS'
|
||||
WHEN pr.pruid = '13' THEN 'NB'
|
||||
WHEN pr.pruid = '24' THEN 'QC'
|
||||
WHEN pr.pruid = '35' THEN 'ON'
|
||||
WHEN pr.pruid = '46' THEN 'MB'
|
||||
WHEN pr.pruid = '47' THEN 'SK'
|
||||
WHEN pr.pruid = '48' THEN 'AB'
|
||||
WHEN pr.pruid = '59' THEN 'BC'
|
||||
WHEN pr.pruid = '60' THEN 'YT'
|
||||
WHEN pr.pruid = '61' THEN 'NT'
|
||||
WHEN pr.pruid = '62' THEN 'NU'
|
||||
END AS pr_iso_code,
|
||||
pr.geom
|
||||
FROM
|
||||
bronze.lpr_000a16a_e AS pr,
|
||||
silver.grc_pr_2016 AS grc
|
||||
WHERE
|
||||
grc.pr_dguid = CONCAT('2016A0002', pr.pruid);
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.pr_2016
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX pr_2016_geom_idx ON pr_2016 USING gist (geom) WITH (
|
||||
fillfactor = 100
|
||||
);
|
||||
Reference in New Issue
Block a user