Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upated COG retrieval and data prep to post 2018 format #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions 00-init.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
createdb
psql -c "CREATE EXTENSION IF NOT EXISTS unaccent;"
psql -c "CREATE EXTENSION postgis;"

28 changes: 13 additions & 15 deletions 25-cog.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
ANNEE=2018
wget -nc https://insee.fr/fr/statistiques/fichier/3363419/comsimp$ANNEE-txt.zip
wget -nc https://insee.fr/fr/statistiques/fichier/3363419/depts$ANNEE-txt.zip
wget -nc https://insee.fr/fr/statistiques/fichier/3363419/reg$ANNEE-txt.zip
unzip -o comsimp2018-txt.zip
unzip -o depts2018-txt.zip
unzip -o reg2018-txt.zip
ANNEE=2023
ID=6800675
wget -nc https://insee.fr/fr/statistiques/fichier/$ID/v_commune_$ANNEE.csv
wget -nc https://insee.fr/fr/statistiques/fichier/$ID/v_departement_$ANNEE.csv
wget -nc https://insee.fr/fr/statistiques/fichier/$ID/v_region_$ANNEE.csv

psql -c "drop table if exists cog_com cascade; create table cog_com (CDC text,CHEFLIEU text,REG text,DEP text,COM text,AR text,CT text,TNCC text,ARTMAJ text,NCC text,ARTMIN text,NCCENR text);"
psql -c "\copy cog_com from comsimp2018.txt with (format csv, header true, delimiter E'\t', encoding 'iso8859-1')"
psql -c "alter table cog_com add depcom text; update cog_com set depcom = dep||com; create index on cog_com (depcom);"
psql -c "drop table if exists cog_com cascade; create table cog_com (TYPECOM text,COM text,REG text,DEP text,CTCD text,ARR text,TNCC text,NCC text,NCCENR text,LIBELLE text,CAN text,COMPARENT text);"
psql -c "\copy cog_com from v_commune_${ANNEE}.csv with (format csv, header true, delimiter ',', encoding 'utf-8')"
psql -c "create index on cog_com (com);"

psql -c "drop table if exists cog_dep; create table cog_dep (REGION text, DEP text,CHEFLIEU text,TNCC text,NCC text,NCCENR text);"
psql -c "\copy cog_dep from depts2018.txt with (format csv, header true, delimiter E'\t', encoding 'iso8859-1')"
psql -c "drop table if exists cog_dep; create table cog_dep (REG text, DEP text,CHEFLIEU text,TNCC text,NCC text,NCCENR text,LIBELLE text);"
psql -c "\copy cog_dep from v_departement_${ANNEE}.csv with (format csv, header true, delimiter ',', encoding 'utf-8')"

psql -c "drop table if exists cog_reg; create table cog_reg (REGION text, CHEFLIEU text,TNCC text,NCC text,NCCENR text);"
psql -c "\copy cog_reg from reg2018.txt with (format csv, header true, delimiter E'\t', encoding 'iso8859-1')"
psql -c "drop table if exists cog_reg; create table cog_reg (REG text, CHEFLIEU text,TNCC text,NCC text,NCCENR text,LIBELLE text);"
psql -c "\copy cog_reg from v_region_${ANNEE}.csv with (format csv, header true, delimiter ',', encoding 'utf-8')"

psql -c "create view cog as (select c.depcom, d.dep, c.nccenr as nomcom, d.nccenr as nomdep, r.nccenr as nomreg from cog_com c join cog_dep d on (c.dep=d.dep) join cog_reg r on (r.region=d.region));"
psql -c "create view cog as (select c.com, d.dep, c.libelle as nomcom, d.libelle as nomdep, r.libelle as nomreg from cog_com c join cog_dep d on (c.dep=d.dep) join cog_reg r on (r.reg=d.reg) where c.typecom='COM');"
3 changes: 2 additions & 1 deletion poi2addok.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ FROM
LEFT JOIN com AS c ON
ST_Intersects(poi.geom, c.geom)
LEFT JOIN cog ON
depcom = c.insee
com = c.insee
;

DROP INDEX IF EXISTS idx_def_tag;
CREATE INDEX idx_def_tag ON def((key1 || '=' || value1));


Expand Down