Changes between Version 29 and Version 30 of CookBook join RHT-BDMAP


Ignore:
Timestamp:
Oct 13, 2011 4:13:02 PM (14 years ago)
Author:
cedric
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CookBook join RHT-BDMAP

    v29 v30  
    106106select count(*) from bdmap2009.station_bdmapv2_final stat inner join bd_carthage2011.troncon_hydrographique as bdc on bdc.code_hydro=stat.eh_codegen; --58875 ca ne marche pas du tout 
    107107}}} 
    108  
    109  
    110 reprojection de bdmap 
    111 {{{ 
     108travail de projection des données 
     109{{{ 
     110#!sql 
     111/*  
     112Travail brouillon intégration bd_map 
     113cedric Briand 13-octobre 2011 
     114*/ 
     115 
     116/*  
     117questions 
     118Laurent 
     119 
     120Est que les points ont été reprojettés. Est ce que comme lannee dernière le fichier correspond à la reprojection de 2008 seulement, 
     121si non avez vous des shapes plus récents : => NON 
     122Est ce que les données correspondent à station st_abcisse_l93 st_ordonnee_l93 ? => NON CES COLONNES SONT VIDES 
     123Si c'est le cas à quoi sert le fichier bdmap2009.station_bdmapv2_final ? => OK VOUS N'AVEZ PAS RETRAVAILLE DESSUS MAIS IL FAUT RECUPERER LES FICHIERS DU RCS POUR AVOIR CERTAINES COORDONNEES MANQUANTES ... AU FINAL IL EN MANQUE PAS BEAUCOUP 
     124Lors de cette reprojection avez vous une table avec les identifiants id_bdcarthage du cours d'eau.... c'est sur cette hypothèse que nous travaillions... 
     125=> CELINE NE PEUT PAS AVANCER RAPIDEMENT AVEC LES DONNEES FOURNIES  ! 
     126 
     127Est ce que station_bdmapv2_final correspond à stationsp2 ? => NON IL FAUT LA REFAIRE 
     128Pourquoi est ce que dans station_bdmapv2_final ? -- 8759 alors que céline select count(*) from bd_map.stationsp2  --10193 lignes 
     129=> PARCE QUE STATIONSP2 EST UNE JOINTURE RIGHT JOIN ENTRE DEUX TABLES 
     130*/ 
     131 
     132-- quelques requêtes pour voir les tables 
     133/* 
     134select * from bdmap2009.station_bdmapv2_final limit 10; 
     135select * from bdmap2009.station limit 100; 
     136select count(*) from bdmap2009.station_bdmapv2_final -- 8759 
     137select count(*) from bdmap2009.station --11379 
     138select * from bd_carthage2011.troncon_hydrographique limit 10; 
     139select distinct on (code_hydro) count(*) from bd_carthage2011.troncon_hydrographique group by code_hydro 
     140-- pas de jointure avec la méthode proposée par Céline 
     141select count(*) from bdmap2009.station_bdmapv2_final stat  
     142inner join bd_carthage2011.troncon_hydrographique as bdc on bdc.code_hydro=stat.th_code --12325 
     143*/ 
     144 
     145-- reprojection de bdmap2009.station_bdmapv2_final 
     146 
    112147alter table bdmap2009.station_bdmapv2_final drop constraint enforce_srid_the_geom; 
    113148update bdmap2009.station_bdmapv2_final set the_geom=st_transform(the_geom,3035); 
    114149alter table bdmap2009.station_bdmapv2_final add constraint enforce_srid_the_geom CHECK (st_srid(the_geom) = 3035); 
    115 }}} 
     150 
     151--select st_transform(PointFromText('POINT(' || st_abcisse || ' ' || st_ordonnee || ')',27572),3035) from bdmap2009.station; 
     152--select * from bdmap2009.station where st_abcisse_l93>0 -- 0 lignes on en peut pas utiliser 
     153 
     154SELECT AddGeometryColumn('bdmap2009', 'station','the_geom', 3035,'POINT',2);  
     155UPDATE bdmap2009.station SET the_geom=st_transform(PointFromText('POINT(' || st_abcisse || ' ' || st_ordonnee || ')',27572),3035); 
     156ALTER TABLE bdmap2009.station SET WITH OIDS; 
     157CREATE INDEX indexStations ON bdmap2009.station 
     158  USING GIST ( the_geom GIST_GEOMETRY_OPS );  
     159 
     160-- il faut aller chercher les stations qui manquent dans bdmap2009.station_bdmapv2_final 
     161 
     162DROP TABLE IF EXISTS bdmap2009.stationsp2; 
     163CREATE TABLE bdmap2009.stationsp2 WITH OIDS AS( 
     164  select  
     165  bdmap2009.station.st_altitude, 
     166  bdmap2009.station.st_abcisse, 
     167  bdmap2009.station.st_codecsp, 
     168  bdmap2009.station.st_datearret, 
     169  bdmap2009.station.st_datecreation, 
     170  bdmap2009.station.st_distancesource, 
     171  bdmap2009.station.st_distancemer, 
     172  bdmap2009.station.st_finalite, 
     173  bdmap2009.station.st_imageign, 
     174  bdmap2009.station.st_imagedept, 
     175  bdmap2009.station.st_lieudit, 
     176  bdmap2009.station.st_limites, 
     177  bdmap2009.station.st_localisation, 
     178  bdmap2009.station.st_longueur, 
     179  bdmap2009.station.st_moduleia, 
     180  bdmap2009.station.st_cd_naturecourseau, 
     181  bdmap2009.station.st_ordonnee, 
     182  bdmap2009.station.st_penteign, 
     183  bdmap2009.station.st_pkaval, 
     184  bdmap2009.station.st_raisremp, 
     185  bdmap2009.station.st_sbv, 
     186  bdmap2009.station.st_t_janvier, 
     187  bdmap2009.station.st_t_juillet, 
     188  bdmap2009.station.st_cd_typecourseau, 
     189  bdmap2009.station.st_cd_tet, 
     190  bdmap2009.station.st_st_id, 
     191  bdmap2009.station.st_cm_id, 
     192  bdmap2009.station.st_cx_id, 
     193  bdmap2009.station.st_th_id, 
     194  bdmap2009.station.st_eh_id, 
     195  bdmap2009.station.st_uh_id, 
     196  bdmap2009.station.st_dt_cre, 
     197  bdmap2009.station.st_dt_maj, 
     198  bdmap2009.station.st_qi_maj, 
     199  bdmap2009.station.st_masseeau, 
     200  CASE WHEN bdmap2009.station_bdmapv2_final.the_geom IS NULL THEN station.the_geom 
     201       ELSE bdmap2009.station_bdmapv2_final.the_geom 
     202       END AS the_geom 
     203  FROM bdmap2009.station_bdmapv2_final right join bdmap2009.station on station_bdmapv2_final.st_codecsp=bdmap2009.station.st_codecsp);--11379 
     204COMMENT ON TABLE bdmap2009.stationsp2 is 'Données BDMAP avec l année 2009 transmises par Laurent Beaulaton bdmap20110803.backup et mise à jour avec les coordonnées reprojetées par Hélène' 
     205 
     206-- je vire les stations hors de France, par rapport à la dernière fois deux sont rentrées en France avec des coordonnées correctes. 
     207delete from bdmap2009.stationsp2 where st_codecsp IN ('03890162','03270062','03270061','03270063','03270064','06260126','06420055','06070241') 
     208 
     209 
     210 
     211 
     212CREATE INDEX indexStationsp2 ON bdmap2009.stationsp2 
     213  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     214 
     215 
     216-- creation de la table bdmap2009.bdmap_rht, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis   
     217DROP TABLE IF EXISTS bdmap2009.bdmap_rht; 
     218CREATE TABLE bdmap2009.bdmap_rht as ( 
     219        SELECT distinct on (st_codecsp) st_codecsp, id_drain, min(distance) as distance, the_geom FROM ( 
     220               SELECT st_codecsp, id_drain ,CAST(distance(r.the_geom, s.the_geom) as  decimal(15,1)) as distance,s.the_geom  
     221               FROM bdmap2009.stationsp2 As s 
     222               INNER JOIN  rht.rht r ON ST_DWithin(r.the_geom, s.the_geom,300) 
     223               WHERE s.the_geom IS NOT NULL 
     224               ORDER BY st_codecsp) AS sub  
     225        GROUP BY st_codecsp, distance,id_drain, the_geom 
     226); 
     227alter table bdmap2009.bdmap_rht add column id serial; 
     228-- mise à jour de la table geometry_columns 
     229INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
     230SELECT '', 'bdmap2009', 'bdmap_rht', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     231FROM bdmap2009.bdmap_rht LIMIT 1; 
     232 
     233-- creation d'index, clé primaire, et constraintes qui vont bien 
     234alter table bdmap2009.bdmap_rht add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     235alter table bdmap2009.bdmap_rht add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     236alter table bdmap2009.bdmap_rht add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     237alter table bdmap2009.bdmap_rht ADD CONSTRAINT pk_id PRIMARY KEY(id); 
     238CREATE INDEX indexbdmap_rht ON bdmap2009.bdmap_rht 
     239  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     240 
     241-- je vire les deux anciennes tables de Céline qui ne servent plus puisque je viens de refaire le travail de projection 
     242 
     243DROP TABLE IF EXISTS rht.bdmap_rht_id; 
     244DROP TABLE IF EXISTS rht.bdmap_rht; 
     245 
     246-- creation de la table bdmap_bd_carthage, je rajoute un the_geom a la requete pour pouvoir voir la table dans Qgis   
     247-- normalement on projette sur la bd_carthage et on utilise la jointure Rht bd_carthage pour récupérer les tronçons. 
     248 
     249 
     250DROP table if exists bdmap2009.bdmap_bd_carthage; 
     251CREATE TABLE bdmap2009.bdmap_bd_carthage as ( 
     252        SELECT distinct on (st_codecsp) st_codecsp,  id_bdcarth, min(distance) as distance, the_geom FROM ( 
     253               SELECT st_codecsp, id_bdcarth ,CAST(distance(r.the_geom, s.the_geom) as  decimal(15,1)) as distance,s.the_geom  
     254               FROM bdmap2009.stationsp2 As s 
     255               INNER JOIN  bd_carthage2011.troncon_hydrographique r ON ST_DWithin(r.the_geom, s.the_geom,300) 
     256               WHERE s.the_geom IS NOT NULL 
     257               AND nature !='Aqueduc, conduite forcée' and num_superp !=1 -- je vire les tronçons superposés. 
     258               ORDER BY st_codecsp) AS sub  
     259        GROUP BY st_codecsp, distance, id_bdcarth, the_geom 
     260);--11181 
     261alter table bdmap2009.bdmap_bd_carthage add column id serial; 
     262-- mise à jour de la table geometry_columns 
     263INSERT INTO geometry_columns(f_table_catalog, f_table_schema, f_table_name, f_geometry_column, coord_dimension, srid, "type") 
     264SELECT '', 'bdmap2009', 'bdmap_bd_carthage', 'the_geom', ST_CoordDim(the_geom), ST_SRID(the_geom), GeometryType(the_geom) 
     265FROM bdmap2009.bdmap_bd_carthage LIMIT 1; 
     266 
     267-- creation d'index, clé primaire, et constraintes qui vont bien 
     268alter table bdmap2009.bdmap_bd_carthage add CONSTRAINT enforce_dims_the_geom CHECK (ndims(the_geom) = 2); 
     269alter table bdmap2009.bdmap_bd_carthage add  CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL); 
     270alter table bdmap2009.bdmap_bd_carthage add  CONSTRAINT enforce_srid_the_geom CHECK (srid(the_geom) = 3035); 
     271CREATE INDEX indexbdmap_ccm ON bdmap2009.bdmap_bd_carthage 
     272  USING GIST ( the_geom GIST_GEOMETRY_OPS ); 
     273 
     274 
     275 
     276  -- vérifications il manque peu de stations 
     277select count(*) from bdmap2009.station --11379 
     278select count(*) from bdmap2009.stationsp2 --11371 0.07 % 
     279select * from bdmap2009.stationsp2 where the_geom is null; -- 110 stations ou il manque la geométrie 
     280select count(*) from bdmap2009.bdmap_bd_carthage; --11181 sur les tronçons hydro 1.74 % 
     281select count(*) from bdmap2009.bdmap_bd_carthage t join  rht.rht_bdcarthage r on r.id_bdcarth=t.id_bdcarth; -- 10998 sur les tronçons du RHT 3.34 % 
     282 
     283}}}