mirror of
https://github.com/dataforcanada/d4c-datapkg-statistical.git
synced 2026-06-13 14:10:55 +02:00
Create 2021 cartographic boundary files
This commit is contained in:
@@ -6,9 +6,9 @@ Geographic Regions of Canada
|
||||
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 geometries. Digital boundary;
|
||||
DROP TABLE IF EXISTS silver.grc_2021_digital;
|
||||
CREATE TABLE silver.grc_2021_digital AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2021A00016' AS grc_dguid,
|
||||
@@ -71,7 +71,7 @@ final AS (
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -82,7 +82,7 @@ final AS (
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -93,7 +93,7 @@ final AS (
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -104,7 +104,7 @@ final AS (
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
@@ -113,14 +113,131 @@ FROM
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2021
|
||||
silver.grc_2021_digital
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2021_geom_idx ON silver.grc_2021
|
||||
CREATE INDEX grc_2021_digital_geom_idx ON silver.grc_2021_digital
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- With geometries. Cartographic boundary;
|
||||
DROP TABLE IF EXISTS silver.grc_2021_cartographic;
|
||||
CREATE TABLE silver.grc_2021_cartographic 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_000b21a_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_000b21a_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_000b21a_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_000b21a_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_digital 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_digital 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_digital 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_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2021_cartographic
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2021_cartographic_geom_idx ON silver.grc_2021_cartographic
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2021 without geometries, and with pr_dguid;
|
||||
@@ -188,7 +305,7 @@ final AS (
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -199,7 +316,7 @@ final AS (
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -210,7 +327,7 @@ final AS (
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -221,7 +338,7 @@ final AS (
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2021 AS country
|
||||
silver.country_2021_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
@@ -232,9 +349,9 @@ FROM
|
||||
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 geometries. Digital boundary;
|
||||
DROP TABLE IF EXISTS silver.grc_2016_digital;
|
||||
CREATE TABLE silver.grc_2016_digital AS
|
||||
WITH territories AS (
|
||||
SELECT
|
||||
'2016A00016' AS grc_dguid,
|
||||
@@ -297,7 +414,7 @@ final AS (
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -308,7 +425,7 @@ final AS (
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -319,7 +436,7 @@ final AS (
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -330,7 +447,7 @@ final AS (
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
@@ -339,14 +456,131 @@ FROM
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2016
|
||||
silver.grc_2016_digital
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2016_geom_idx ON silver.grc_2016
|
||||
CREATE INDEX grc_2016_digital_geom_idx ON silver.grc_2016_digital
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- With geometries. Cartographic boundary;
|
||||
DROP TABLE IF EXISTS silver.grc_2016_cartographic;
|
||||
CREATE TABLE silver.grc_2016_cartographic 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_000b16a_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_000b16a_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_000b16a_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_000b16a_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_digital 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_digital 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_digital 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_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
FROM
|
||||
final;
|
||||
|
||||
-- Make geometries valid
|
||||
UPDATE
|
||||
silver.grc_2016_cartographic
|
||||
SET
|
||||
geom = ST_MAKEVALID(geom)
|
||||
WHERE
|
||||
ST_ISVALID(geom) = 'f';
|
||||
|
||||
-- Create spatial index
|
||||
CREATE INDEX grc_2016_cartographic_geom_idx ON silver.grc_2016_cartographic
|
||||
USING gist (geom) WITH (fillfactor = 100);
|
||||
|
||||
-- 2016 without geometries, and with pr_dguid;
|
||||
@@ -415,7 +649,7 @@ final AS (
|
||||
territories.*
|
||||
FROM
|
||||
territories,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -426,7 +660,7 @@ final AS (
|
||||
prairies.*
|
||||
FROM
|
||||
prairies,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -437,7 +671,7 @@ final AS (
|
||||
atlantic.*
|
||||
FROM
|
||||
atlantic,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
UNION
|
||||
SELECT
|
||||
country.country_dguid,
|
||||
@@ -448,7 +682,7 @@ final AS (
|
||||
the_rest.*
|
||||
FROM
|
||||
the_rest,
|
||||
silver.country_2016 AS country
|
||||
silver.country_2016_digital AS country
|
||||
)
|
||||
|
||||
SELECT *
|
||||
|
||||
Reference in New Issue
Block a user