Vedène -
C'est un excellent test pour valider l'industrialisation du processus. Vedène (84141) va nous permettre de vérifier si la structure à 40 colonnes est constante.
Voici le plan d'action séquentiel.
1. Création de vedene_full (Le moule brut)
On prépare d'abord le réceptacle pour l'importation du CSV.
SQL
docker exec -i alteris_postgis psql -U alteris_admin -d alteris_geo -c "
CREATE SCHEMA IF NOT EXISTS dvf_raw;
DROP TABLE IF EXISTS dvf_raw.vedene_full;
CREATE TABLE dvf_raw.vedene_full (
c1 text, c2 text, c3 text, c4 text, c5 text, c6 text, c7 text, c8 text, c9 text, c10 text,
c11 text, c12 text, c13 text, c14 text, c15 text, c16 text, c17 text, c18 text, c19 text, c20 text,
c21 text, c22 text, c23 text, c24 text, c25 text, c26 text, c27 text, c28 text, c29 text, c30 text,
c31 text, c32 text, c33 text, c34 text, c35 text, c36 text, c37 text, c38 text, c39 text, c40 text
);
"
2. Injection des données (Bash/Docker)
Assure-toi que le fichier est bien présent dans ton arborescence locale avant de lancer :
Bash
# 1. Injection du CSV (40 colonnes)
cat "/home/debian/data/Regions/93/84/248400251/84141/84141.csv" | docker exec -i alteris_postgis psql -U alteris_admin -d alteris_geo -c "COPY dvf_raw.vedene_full FROM STDIN WITH (FORMAT CSV, HEADER, DELIMITER ',');"
# 2. Création du Jalon Géographique (Points Lambert 93)
docker exec -i alteris_postgis psql -U alteris_admin -d alteris_geo -c "
DROP TABLE IF EXISTS dvf_raw.vedene_valide;
CREATE TABLE dvf_raw.vedene_valide AS
SELECT
f.c1 as id_mutation,
ST_Transform(ST_SetSRID(ST_MakePoint(NULLIF(f.c39, '')::double precision, NULLIF(f.c40, '')::double precision), 4326), 2154) as geom
FROM dvf_raw.vedene_full f
WHERE f.c39 ~ '^-?[0-9]';
CREATE INDEX sidx_vedene_valide ON dvf_raw.vedene_valide USING GIST (geom);
"
3. Création de vedene_valide (Le Jalon Géographique)
On extrait les points GPS pour "poser le premier jalon" et vérifier l'emprise.
SQL
DROP TABLE IF EXISTS dvf_raw.vedene_valide;
CREATE TABLE dvf_raw.vedene_valide AS
SELECT
f.c1 as id_mutation,
ST_Transform(ST_SetSRID(ST_MakePoint(NULLIF(f.c39, '')::double precision, NULLIF(f.c40, '')::double precision), 4326), 2154) as geom
FROM dvf_raw.vedene_full f
WHERE f.c39 ~ '^-?[0-9]';
CREATE INDEX sidx_vedene_valide ON dvf_raw.vedene_valide USING GIST (geom);
4. Fusion Finale : 84141_dvf_alteris (L'Item Unique)
On assemble le tout (DVF + Géométrie Validée + Jointure Cadastre) en éliminant les doublons de lignes DVF.
SQL
DROP TABLE IF EXISTS dvf_raw."84141_dvf_alteris";
CREATE TABLE dvf_raw."84141_dvf_alteris" AS
WITH cadastre AS (
-- Reconstruction spatiale du cadastre de Vedène
SELECT
(f->'properties'->>'id')::text as id_parcelle_cad,
ST_Transform(ST_SetSRID(ST_GeomFromGeoJSON(f->'geometry'), 4326), 2154) as geom_poly
FROM (
SELECT jsonb_array_elements(string_agg(line, '')::jsonb->'features') as f
FROM dvf_raw.tmp_vedene_txt
) sub
)
SELECT DISTINCT ON (f.c1)
v.geom,
f.c1 as id_mutation,
NULLIF(f.c2, '')::date as date_mutation,
NULLIF(f.c5, '')::numeric as valeur_fonciere,
f.c16 as id_parcelle_dvf,
f.c8 || ' ' || f.c9 as adresse,
f.c28 as type_local,
NULLIF(f.c29, '')::numeric as surface_bati,
ST_Within(v.geom, c.geom_poly) as certification_spatiale
FROM dvf_raw.vedene_full f
JOIN dvf_raw.vedene_valide v ON f.c1 = v.id_mutation
LEFT JOIN cadastre c ON f.c16 = c.id_parcelle_cad
ORDER BY f.c1;
-- Nettoyage des tables temporaires
DROP TABLE dvf_raw.tmp_vedene_txt;
Chiche ! Les scripts sont prêts. Tu veux que je lance l'exécution ou tu préfères vérifier un point de structure avant ?
No comments to display
No comments to display